日期:2014-05-20  浏览次数:20838 次

java se 不知道错哪里?
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.java

D:\java\digui>java SuperConstructSample
Exception in thread "main" java.lang.NoSuchMethodError: BoxAttribute.
ate()D
        at SuperConstructSample.main(SuperConstructSample.java:35)


------解决方案--------------------
楼主class SuperConstructSample前加上public
------解决方案--------------------
你这个写的没有问题,你如果用命令行的话,三个类文件分开,要分别编译成class文件,再执行主类,如果你的类没有public修饰,只能在一个包中用其他类的变量或方法。。。
------解决方案--------------------
楼主是否把文件弄错了? 看看你自己的文件的35行.
------解决方案--------------------
加public