class Demo {
public static void main(String[] args) {
Phone p = new Phone("三星",998);
p.show();
Phone p1 = new Phone();
p1.setBrand("华为");
p1.getBrand();
p1.setPrice(5678);
p1.getPrice();
p1.show();
}
}
class Phone {
private String brand;
private int price;
public Phone() {}
public Phone(String brand,int price ) {
this.brand = brand;
this.price = price;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getBrand() {
return brand;
}
public void setPrice(int price) {
this.price =price;
}
public int getPrice() {
return price;
}
public void show() {
System.out.println("手机的品牌是:"+brand+",价格是:"+price);
}
}
|
|