- public class Box {
- double weith;
- double height;
- double depth;
- Box(double w,double h,double d){
- //this总是调用该方法的一个引用,可以在当前类的类型所允许对象的任何地方将this作为一个引用
- this.weith=w;
- this.height=h;
- this.depth=d;
-
- }
- }
- class BoxWeight extends Box{
- double weight;
- BoxWeight(double w,double h,double d,double m){
- super(w,h,d); //调用父类的构造方法,BoxWeight不再初始化这三个值
- this.weight=m;
-
- }
- }
复制代码 |