* 每一款手机都有自己的品牌和价格,原来的手机只能打电话,发短信;现在的新手机,
在打电话和发短信的基础上还能玩儿游戏,请设计程序,完成手机的升级!
public class Test {
public static void main(String[] args) {
//创建新手机对象
NewPhone phone=new NewPhone("小米",1999);
System.out.println("新手机的品牌为:"+phone.getBrand()+" "+"新手机的价格为"+phone.getPirce());
phone.call();
phone.takeMessage();
phone.playGame();
}
}
public class Phone {
private String brand;
private int pirce;
public Phone(String brand, int pirce) {
super();
this.brand = brand;
this.pirce = pirce;
}
public Phone() {
super();
// TODO Auto-generated constructor stub
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public int getPirce() {
return pirce;
}
public void setPirce(int pirce) {
this.pirce = pirce;
}
@Override
public String toString() {
return "Phone [brand=" + brand + ", pirce=" + pirce + "]";
}
public void call() {
System.out.println("打电话");
}
public void takeMessage() {
System.out.println("发短信");
}
}
public class NewPhone extends Phone {
public NewPhone() {
super();
// TODO Auto-generated constructor stub
}
public NewPhone(String brand, int pirce) {
super(brand, pirce);
// TODO Auto-generated constructor stub
}
public void playGame() {
System.out.println("玩王者荣耀");
}
}