JAVA 8-1 继承的练习

People父类:

 

public class People {
	
	float height = 0.0f;
	int weight = 0;
	
	People()
	{
		this.height = height;
		this.weight = weight;
	}
	
	public void speakHello()
	{
		System.out.println("你好");
	}


	
	public void averageWeight()
	{
		
	}
	
	public void averageHeight()
	{
	}	
ChinaPeople 子类:


 

public class  ChinaPeople extends People {
	
	ChinaPeople()
	{
		this.height = height;
		this.weight = weight;
	}
	
	public void chinaMartial()
	{
		System.out.println("中国是崇尚和平的,人不犯我我不犯人,人若犯我,嘿嘿~~");
	}
	
	public void averageWeight()
	{
		weight = 110;
		System.out.println("中国人平均体重是   "+weight);
	}
	
	public void averageHeight()
	{
		height = 1.75f;
		System.out.println("中国人平均身高是   "+height);
	}
	
	public void speakHello()
	{
		System.out.println("中国你好");
	}

}


  AmaricanPeople子类:

public class AmericanPeople extends People {
	
	AmericanPeople()
	{
		this.height = height;
		this.weight = weight;
	}
	
	public void AmericanBoxing()
	{
		System.out.println("美国的拳击超棒 , 看看WWE你就知道到底有多帅了");
	}
	
	public void averageWeight()
	{
		weight = 120;
		System.out.println("美国人平均体重是   "+weight);
	}
	
	public void averageHeight()
	{
		height = 1.80f;
		System.out.println("美国人平均身高是   "+height);
	}
	
	public void speakHello()
	{
		System.out.println("美国你好");
	}


}


BeijingPeople 子类:

 

public class BeijingPeople  extends ChinaPeople {
	
	BeijingPeople()
	{
		this.height = height;
		this.weight = weight;
	}
	
	public void BeijingOpera()
	{
		System.out.println("京剧源远流长 , so cool");
	}
	
	public void averageWeight()
	{
		weight = 110;
		System.out.println("北京人平均体重是   "+weight);
	}
	
	public void averageHeight()
	{
		height = 1.75f;
		System.out.println("北京人平均身高是   "+height);
	}
	
	public void speakHello()
	{
		System.out.println("北京人你好");
	}
	
	

}


 

Test 测试类:

 

public class Test {
	
	public static void main(String args[])
	{
	
		People p = new People();
		p.speakHello();
		
		ChinaPeople c = new ChinaPeople();
		c.speakHello();
		c.chinaMartial();
		c.averageHeight();
		c.averageWeight();
		
		AmericanPeople a = new AmericanPeople();
		a.speakHello();
		a.AmericanBoxing();
		a.averageHeight();
		a.averageWeight();
		
		BeijingPeople  b = new BeijingPeople ();
		b.speakHello();
		b.BeijingOpera();
		b.averageHeight();
		b.averageWeight();
		
		
	}

}


 

运行结果:

你好
中国你好
中国是崇尚和平的,人不犯我我不犯人,人若犯我,嘿嘿~~
中国人平均身高是   1.75
中国人平均体重是   110
美国你好
美国的拳击超棒 , 看看WWE你就知道到底有多帅了
美国人平均身高是   1.8
美国人平均体重是   120
北京人你好
京剧源远流长 , so cool
北京人平均身高是   1.75
北京人平均体重是   110

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值