JAVA程序设计基础实验三 .pdf
实验报告三
课程JAVA语言程序设计实验项目继承与接口成绩
学号XXXXXX姓名XXXXX实验日期2012/10/13
专业班级计算机科学与技术09级指导教师XXXXX
一【实验目的】
(1)掌握类和对象的创建方法
(2)理解继承的相关概念
(3)掌握子类对象的创建过程
(4)掌握方法的继承与重写
(5)理解多态的概念与上转型对象
(6)理解抽象类和接口的概念及特点
二【实验内容】
【项目一】方法重写
定义父类People,分别定义People类的子类ChinaPeople,AmericanPeople和BeijingPeople
并分别重写父类中的各个方法。最后在主方法中分别创建各子类的对象并调用各自的方法打
印输出信息。该程序的模板代码见/附件/Example.java:请将其补充完整并调试运行。
(1)程序代码
classPeople
{
protecteddoubleweight,height;
publicvoidspeakHello()
{
System.out.println(yayawawa);
}
publicvoidaverageHeight()
{
height=173;
System.out.println(averageheight:+height);
}
publicvoidaverageWeight()
{
weight=70;
System.out.println(averageweight:+weight);
}
}
classChinaPeopleextendsPeople
{
//doubleweight,height;
//重写publicvoidspeakHello()方法,要求输出类似“你好,吃了吗”这样的
//汉语信息
publicvoidspeakHello()
{
System.out.println(你好,你吃了吗?);
}
//重写publicvoidaverageHeight()方法,要求输出类似
//“中国人的平均身高:168.78厘米”这样的汉语信息
publicvoidaverageHeight()
{
height=168.78;
System.out.println(中国人的平均身高:+height);
}
//重写publicvoidaverageWeight()方法,
//要求输出类似“中国人的平均体重:65公斤”这样的汉语信息
publicvoidaverageWeight()
{
weight=65;
System.out.println(中国人的平均体重:+weight);
}
publicvoidchinaGongfu()
{
//输出中国武术的信息,例如:坐如钟,站如松,睡如弓等
System.out.println(坐如钟,站如松,睡如弓);
}
}
classAmericanPeopleextendsPeople
{
//重写publicvoidspeakHello()方法,要求输出类似
//“Howdoyoudo”这样的英语信息。
publicvoidspeakHello()
{
System.out.println(Howdoyoudo);
}
//重写publicvoidaverageHeight()方法
publicvoidave