两种属性赋值方法 构造函数和SetXXX方法
class Demo3_Phone
{
public static void main(String[] args)
{
Phone p=new Phone();
p.setBrand("三星");
p.setPrice(1288);
System.out.println(p.getBrand()+"-----"+p.getPrice());
p.call();
p.sendMessage();
p.palyGame();
}
}
class Phone{
private String brand;
private int price;
public void call(){
System.out.println("打电话");
}
public void sendMessage(){
System.out.println("发短信");
}
public void palyGame(){
System.out.println("玩游戏");
}
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;
}
}
|
|