JAVA大学实用教程实验指导5.2.1答案

P39       继承             代码补完

 

 

 

Example.java

  1. class People
  2. {
  3.     protected double weight,height;
  4.     public void speakHello()
  5.     {
  6.         System.out.println("yayawawa");
  7.     }
  8.     public void averageHeight()
  9.     {
  10.         height=173;
  11.         System.out.println("average height:"+height);
  12.     }
  13.     public void averageWeight()
  14.     {
  15.         weight=70;
  16.         System.out.println("average weight:"+weight);
  17.     }
  18. }
  19. class ChinaPeople extends People
  20. {
  21.     public void speakHello()
  22.     {
  23.         System.out.println("你好,吃了吗?");
  24.     }
  25.     public void averageHeight()
  26.     {
  27.         System.out.println("中国人的平均身高:168.78厘米");
  28.     }
  29.     public void averageWeight()
  30.     {
  31.         System.out.println("中国人的平均体重:65公斤");
  32.     }
  33.     public void chinaGongfu()
  34.     {
  35.         System.out.println("坐如钟,站如松,睡如弓");
  36.     }
  37. }
  38. class AmericanPeople extends People
  39. {
  40.     public void speakHello()
  41.     {
  42.         System.out.println("How do you do?");
  43.     }
  44.     public void averageHeight()
  45.     {
  46.         System.out.println("Amerian Average height:188.0 cm");
  47.     }
  48.     public void averageWeight()
  49.     {
  50.         System.out.println("Amerian Average weight:82.23 kg");
  51.     }
  52.     public void americanBoxing()
  53.     {
  54.         System.out.println("直拳,钩拳");
  55.     }
  56. }
  57. class BeijingPeople extends ChinaPeople
  58. {
  59.     public void speakHello()
  60.     {
  61.         System.out.println("您好");
  62.     }
  63.     public void averageHeight()
  64.     {
  65.         System.out.println("北京人的平均身高:166.0厘米");
  66.     }
  67.     public void averageWeight()
  68.     {
  69.         System.out.println("北京人的平均体重:67.4公斤");
  70.     }
  71.     public void beijingOpera()
  72.     {
  73.         System.out.println("京剧术语");
  74.     }
  75. }
  76. public class Example
  77. {
  78.     public static void main(String args[])
  79.     {
  80.         ChinaPeople chinaPeople=new ChinaPeople();
  81.         AmericanPeople americanPeople=new AmericanPeople();
  82.         BeijingPeople beijingPeople=new BeijingPeople();
  83.         chinaPeople.speakHello();
  84.         americanPeople.speakHello();
  85.         beijingPeople.speakHello();
  86.         chinaPeople.averageHeight();
  87.         americanPeople.averageHeight();
  88.         beijingPeople.averageHeight();
  89.         chinaPeople.averageWeight();
  90.         americanPeople.averageWeight();
  91.         beijingPeople.averageWeight();
  92.         chinaPeople.chinaGongfu();
  93.         americanPeople.americanBoxing();
  94.         beijingPeople.beijingOpera();
  95.         beijingPeople.chinaGongfu();
  96.     }
  97. }
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值