每一款手机都有自己的品牌和价格,原来的手机只能打电话,发短信,来电显示只能显示手机号;
* 现在的新手机针对于来电显示做了功能的升级,还能显示头像,还能显示归属地,请设计程序,完成手机的升级!
public class test {
public static void main(String[] args) {
//创建子类对象
NewPhone phone=new NewPhone("华为",4799);
System.out.println("新手机的价格:"+phone.getBrand()+" "+"新手机的价格"+phone.getPrice());
phone.call();
phone.TakeMessage();
phone.show();
}
}
public class OldPhone {
private String brand;
private int price;
public OldPhone() {
super();
// TODO Auto-generated constructor stub
}
public OldPhone(String brand, int price) {
super();
this.brand = brand;
this.price = price;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public int getPrice() {
return price;
}
public void setAge(int age) {
this.price = age;
}
@Override
public String toString() {
return "OldPhone [brande=" + brand + ", age=" + price + "]";
}
public void call() {
System.out.println("打电话");
}
public void TakeMessage() {
System.out.println("发短信");
}
public void show() {//来电显示
System.out.println("只能显示手机号");
}
}
public class NewPhone extends OldPhone {
public NewPhone() {
super();
// TODO Auto-generated constructor stub
}
public NewPhone(String price, int age) {
super(price, age);
// TODO Auto-generated constructor stub
}
@Override
public String toString() {
return "NewPhone [getPrice()=" + getPrice() + ", getPrice()=" + getPrice() + ", toString()=" + super.toString()
+ ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + "]";
}
public void show() {//来电显示
System.out.println("还能显示头像,还能显示归属地");
}
}