实验项目 2Java 面对对象程序设计第 2 部分继承与接口[实验目的]1、 掌握 java 继承中父类及其子类的定义方法
2、 掌握子类重写父类同名方法的方法
3、 掌握接口的用法
[实验要求]1、 复习理论教学中所学的内容
2、仔细进行实验预习, 查阅参考书, 书写源程序, 书写实验预习报告
3、仔细总结实验并书写实验报告
[实验课时]2 学时[实验教学方式]学生上机实验, 老师随堂指导
[实验内容]1、 定义父类 People, 分别定义 People 类的子类 ChinaPeople, AmericanPeople 和 BeijingPeople 并分别重写父类中的各个方法
最后在主方法中分别创立各子类的对象并调用各自的方法打印输出信息
该程序的模板代码如下: 请将其补充完整并调试运行
classPeople{protecteddoubleweight,height;publicvoidspeakHello(){System
println("yayawawa");}publicvoidaverageHeight(){height=173;System
println("averageheight:"+height);}publicvoidaverageWeight(){weight=70;System
println("averageweight:"+weight);}}classChinaPeopleextendsPeople{【代码 1】//重写 publicvoidspeakHello()方法, 要求输出类似”你好, 吃了吗”这样的//汉语信息【代码 2】//重写 publicvoidaverageHeight()方法, 要求输出类似//”中国人的平均身高: 168
78 厘米”这样的汉语信息【代码 3】//重写 publicvoid