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)

解决方案 »

  1.   

    楼主class SuperConstructSample前加上public
      

  2.   

    你这个写的没有问题,你如果用命令行的话,三个类文件分开,要分别编译成class文件,再执行主类,如果你的类没有public修饰,只能在一个包中用其他类的变量或方法
      

  3.   

    可以运行啊!volume of box1 is210000.0
    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
      

  4.   

    难道是我classpath的问题?
      

  5.   

    不能识别volumeCaculate方法,class和方法 都加上public