class Phone { //定义手机类
public static void main(String[] args) {
Iphone s = new Iphone();
s.setBrand ( "sumung");
s.setPrice (3999);
System.out.println(s.getBrand() + "..." + s.getPrice());
s.call();
s.sendMessage();
}
}
class Iphone {
private String brand; //定义成员变量,在类中,方法外
private int 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 call(){
System.out.println("打电话");
}
public void sendMessage(){
System.out.println("发信息");
}
public void playGame(){
System.out.println("玩游戏");
}
}
|
|