本文由chasewade贡献
第 4 章类和对象的高级特征
第 4 章类和对象的高级特征
【实验目标】完成本章的内容以后,您将达到: 理解类和对象理解抽象和封装理解对象与类之间的关系掌握包的创建和导入
1G ——《移动通信软件编程基础——Java》实验手册
本章实验给出了全面的操作步骤,请学生按照给出的步骤独立完成实验,以达到要求的实验目标。?
第一阶段——指导学****40 分钟分钟) 第一阶段——指导学****指导学****br/>编写一个 ,编译并运行 1) 建立文件名为“”,输入以下程序代码。[注意:Java 文件名必须与用 public 修饰的类名保持一致]
.; /** * 超类Box * ***@ 2008年7月27日* ***@author xx */ class Box { double width; double height; double depth; /** *构造方法重载*/ Box(double w, double h, double d) { width = w; height = h; depth = d; } /** *构造方法重载*/ Box(double len) { width = height = depth = len; } double volume() {
第 4 章类和对象的高级特征
return width * height * depth; } } /** * BoxWeight继承类Box * ***@ 2008年7月27日* ***@author xx */ class BoxWeight extends Box { double weight; /** *构造方法重载*/ BoxWeight(double w, double h, double d,double m) { super(w,h,d); weight=m; } /** *构造方法重载*/ BoxWeight(double len,double m) { super(len); weight=m; } /** *方法重写*/ double volume() { return width + height + depth; } } /** * BoxCost继承类BoxWeight
1G ——《移动通信软件编程基础——Java》实验手册
***@ 2008年7月27日* ***@author xx */ class BoxCost extends BoxWeight { double cost; /** *构造方法重载*/ BoxCost(double w,double h,double d,double m,double c) { super(w,h,d,m); cost=c; } /** *构造方法重载*/ BoxCost(double len,double m,double c) { super(len,m); cost=c; } /** *方法重写*/ double volume() { return width*2; } } /**
《移动通信软件编程基础-JAVA》第四章(上) 一个习题 来自淘豆网www.taodocs.com转载请标明出处.