class ProductAttribute{
double width,length,height;
ProductAttribute(double x){
width = length = height = x;
}
ProductAttribute (double x ,double y,double z){
width = x;
length = y;
height = z;
}
double volumeCaculate(){
return width*length*height;
}
}class BoxAttribute extends ProductAttribute{
double weight;
BoxAttribute(double x ,double y,double z,double t){
super(x,y,z);
weight = t;
}
BoxAttribute(double x,double t){
super(x);
weight = t;
}
void show(){
System.out.println("width,length,height and weight are "+width+","+length+","+height+"weight");
}
} class SuperConstructSample{
public static void main(String args[]){
double volume;
BoxAttribute box1 = new BoxAttribute(50,60,70,80);
volume = box1.volumeCaculate();
System.out.println("volume of box1 is"+volume);
box1.show();
BoxAttribute box2 = new BoxAttribute(50,80);
volume = box2.volumeCaculate();
System.out.println("volume of box2 is "+volume);
box2.show();
}
}
D:\java\digui>javac SuperConstructSample.javaD:\java\digui>java SuperConstructSample
Exception in thread "main" java.lang.NoSuchMethodError: BoxAttribute.
ate()D
at SuperConstructSample.main(SuperConstructSample.java:35)
double width,length,height;
ProductAttribute(double x){
width = length = height = x;
}
ProductAttribute (double x ,double y,double z){
width = x;
length = y;
height = z;
}
double volumeCaculate(){
return width*length*height;
}
}class BoxAttribute extends ProductAttribute{
double weight;
BoxAttribute(double x ,double y,double z,double t){
super(x,y,z);
weight = t;
}
BoxAttribute(double x,double t){
super(x);
weight = t;
}
void show(){
System.out.println("width,length,height and weight are "+width+","+length+","+height+"weight");
}
} class SuperConstructSample{
public static void main(String args[]){
double volume;
BoxAttribute box1 = new BoxAttribute(50,60,70,80);
volume = box1.volumeCaculate();
System.out.println("volume of box1 is"+volume);
box1.show();
BoxAttribute box2 = new BoxAttribute(50,80);
volume = box2.volumeCaculate();
System.out.println("volume of box2 is "+volume);
box2.show();
}
}
D:\java\digui>javac SuperConstructSample.javaD:\java\digui>java SuperConstructSample
Exception in thread "main" java.lang.NoSuchMethodError: BoxAttribute.
ate()D
at SuperConstructSample.main(SuperConstructSample.java:35)
width,length,height and weight are 50.0,60.0,70.0weight
volume of box2 is 125000.0
width,length,height and weight are 50.0,50.0,50.0weight