DemoBoxWeight

class Box{
double width;
double depth;
double height;
Box(){
width=0;height=0;depth=0;
}
Box(double w,double h,double d){
width=w;depth=d;height = h;
}
double volume(){
return width*height*depth;
}
}
class BoxWeight extends Box{
double weight;
BoxWeight(double w,double h,double d,double m){
width=w;depth=d;height = h;weight=m;
}
}
public class DemoBoxWeight {

public static void main(String[] args) {
// TODO 自动生成的方法存根
BoxWeight mybox1=new BoxWeight(10,20,30,58.5);
BoxWeight mybox2=new BoxWeight(3,5,8,30.5);
System.out.println("Volume of mybox1 is "+mybox1.volume() );
System.out.println("Weight of mybox1 is "+mybox1.weight );
System.out.println("Volume of mybox2 is "+mybox2.volume() );
System.out.println("Volume of mybox2 is "+mybox2.weight);
}

}

原文地址:https://www.cnblogs.com/wlp1115/p/6704914.html