面向对象练习_01

* 每一款手机都有自己的品牌和价格,原来的手机只能打电话,发短信;现在的新手机,
    在打电话和发短信的基础上还能玩儿游戏,请设计程序,完成手机的升级!

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("玩王者荣耀");
	}
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值