首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

java se 不知道错哪儿

2013-03-21 
java se 不知道错哪里?class ProductAttribute{double width,length,heightProductAttribute(double x){w

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

热点排行