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

java 简单的疑问?
class ProductAttribute{
double width,length,height;
ProductAttribute(double x,double y,double z){
width = x;
length = y;
height = z ;
}
double volumeCaculate(){
return width*length*height;
}
public void showSize(){
System.out.println("width length height are "+width+","+length+","+height);
}
}

 class TVAttribute extends ProductAttribute{
double price ;
TVAttribute (double x ,double y,double z ,double p){
super (x,y,z);
price = p;
}
public void showPrice(){
System.out.println("the price is "+price);
}
}

 class ColorTVAttribute extends TVAttribute{
double price ;
String TradeMark;
ColorTVAttribute (double x ,double y,double z,double p,String mark){
super(x,y,z,p);
TradeMark = mark;
}
public void showTradeMark(){
System.out.println("the trade mark is "+TradeMark);
}
}



 class MultiLevelsInheritance{
public static void main(String args[]){
double volume;
ColorTVAttribute colorTV = new ColorTVAttribute(50,60,70,80,"sony");
volume = colorTV.volumeCaculate();
System.out.println("volume is of colorTV "+volume);
colorTV.showSize();
colorTV.showPrice();
colorTV.showTradeMark();
}
}



为什么出现::
D:\java\digui>java MultiLevelsInheritance
volume is of colorTV 210000.0
Exception in thread "main" java.lang.NoSuchMethodError: ColorTVAttribute.showSiz
e()V
        at MultiLevelsInheritance.main(MultiLevelsInheritance.java:47)

为什么会找不到!

------解决方案--------------------
运行了一遍楼主的代码,没有任何问题。
检查一下原本的代码和贴到论坛的代码有什么区别,是不是有拼写错误。
------解决方案--------------------
我运行了一下楼主的代码,没有发现问题。
后台的输出结果:
volume is of colorTV 210000.0
width length height are 50.0,60.0,70.0
the price is 80.0
the trade mark is sony
------解决方案--------------------
Exception in thread "main" java.lang.NoSuchMethodError: ColorTVAttribute.showSiz
e()V
        at MultiLevelsInheritance.main(MultiLevelsInheritance.java:47)

给出的错误提示是:
没有这个方法 ColorTVAttribute.showSize()V
而造成的错误,错误出现在第47行处