public class Demo07_phone { public static void main(String[]args){
phone s1=new phone("三星",3888);//使用有参构造
s1.show();
phone s2=new phone();
s2.setBrand("apple");
s2.setPrice(8888);
System.out.println("手机的品牌是"+s2.getBrand());
System.out.println("手机的价格是"+s2.getPrice());
}
}
class phone{
private String brand;
private int price;
public phone(){
}
public phone(String brand,int price){
this.brand=brand;
this.price=price;
}
public void setPrice(int price) {
this.price = price;
}
public int getPrice() {
return this.price;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getBrand() {
return this.brand;
}
public void show(){
System.out.println("手机的品牌是"+brand);
System.out.println("手机的价格是"+price);
}
}