实验编号:B07039402
| 班 级 | xxxx | 学号 | xxxx | 姓名 | xxxxx | |
| 实验地点 | xxxx | 时间(教学周) | xxx | |||
| 实验名称 | 继承与接口 | |||||
| 实验目的 | 训练目的继承父类与使用接口 | |||||
| 实验环境 | Java jdk1.6.0与eclipse软件开发环境 | |||||
| 实验内容 | ||||||
| 1、继承父类; 2、成员变量的隐藏; 3、方法的重写; 4、定义父类; 5、 | ||||||
| 实验步骤 | ||||||
| 建立工程、建立新类。先观察程序代码,预测运行结果,输入程序代码并运行,查看运行结果,是否与预测的相同,进行分析,最终得出结论。 | ||||||
| 实验结果与讨论(实验结论、技术讨论) | ||||||
| 第一个程序的结果为15.0 8.0#用到定义父类、父类的继承; 第二个程序的结果为 98.0 12#成员变量的隐藏、方法重写; superde 运用; | ||||||
| 附录 | ||||||
| 第一个程序 | 第二个程序 | |||||
| class A{ double f(double x, double y) { return x+y; } } class B extends A { double f( int x, int y){ return x*y; } } public class E { public static void main (String args[]) { B b = new B( ); System.out.println(b.f(3,5)); System.out.println(b.f(3.0,5.0)); } } | Class A{ Double f(double x, double y) { return x+y ; } Static int g(int n) { return n*n; } } class B extends A{ double f(double x, double y ) { double m =super.f(x,y); return m + x*y; } static int g(int n) { int m =A.g(n); return m+n; } } puplic classE{ public static void main (String args[]){ B b = new B(); System.out.println(b.f(10.0 ,8.0)); System.out.println(b.g(3)); } } | |||||
| 教师评语 | 成绩 | |||||