面向对象_02

每一款手机都有自己的品牌和价格,原来的手机只能打电话,发短信,来电显示只能显示手机号;
*  现在的新手机针对于来电显示做了功能的升级,还能显示头像,还能显示归属地,请设计程序,完成手机的升级!

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("还能显示头像,还能显示归属地");
	}
}

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值