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

Java报错
public class AreaCal {  
  
    /* 计算长方形的面积 */  
    public int area(int width, int height) { 
         /*
 this.width=width;
         this.height=height;
*/  
        return width * height;  
    }  
  
    /* 计算正方形的面积 */  
    public int area(int edge) { 
/*
         this.edge=edge;
*/  
        return edge * edge;  
    }  
  
    /* 计算圆的面积 */  
    public double area(float radius) {  
/*
    this.radius=radius;
*/
        return 3.14 * radius * radius;  
    } 

  public  static void main(String[] args)
   { 
      AreaCal a = new AreaCal();
  
      a.area(12,2);
  a.area(5);
  a.area(6);
/*
  System.out.println( );
  System.out.println();
  System.out.println( a.area(6.2));
  */
   }
}  
这个程序报无法加载主类
Java基础

------解决方案--------------------
'this.width=width;'类似的语句,this.width是什么?没有声明这些变量,主类AreaCal 就是错误的,当然没有办法加载。应当首先声明这些变量再使用
在程序前加上以下代码:
int height;
int width;
int edge;
int radius; 


------解决方案--------------------
主类里根本就没有height、width等成员变量...