- public class Phone {
- private String brand;
- private String price;
- private static int size;
- public void show(){
- System.out.println(brand+" "+ price+"元 "+size+"寸");
- }
- public Phone(String brand, String price) {
- this.brand = brand;
- this.price = price;
- }
- public Phone() {
- }
- public String getBrand() {
- return brand;
- }
- public void setBrand(String brand) {
- this.brand = brand;
- }
- public String getPrice() {
- return price;
- }
- public void setPrice(String price) {
- this.price = price;
- }
- public static int getSize() {
- return size;
- }
- public static void setSize(int size) {
- Phone.size = size;
- }
- public void call(){
- System.out.println("打电话");
- }
- public void sendMessage(){
- System.out.println("发短信");
- }
- public void playGame(){
- System.out.println("玩游戏");
- }
- }
- [code]public class Dome {
- public static void main(String[] args) {
- Phone.setSize(6);
- Phone a = new Phone("小米","3999");
- Phone b = new Phone("华为","4999");
- a.show();
- b.show();
- }
- }
复制代码 [/code] |
|