用接口、抽象类、继承三种方法实现各种几何物体面积的计算补充:
下面我用继承的方法做调试有问题:
class Shape{
public double getArea();
}
class Circle extends Shape{
public static final double PI=3.14159; 
private double r; 
public Circle(double r){ 
this.r=r; 

public double getr(){ 
return r; 

public double getArea(){ 
return Math.PI*r*r; 

}class Rectangle extends Shape{ 
private double length; //定义长变量 
private double width; // 宽变量 
public Rectangle(double length,double width){ 
this.length=length; 
this.width=width; 

public double getlength(){ 
return length;
}
public double getwidth(){ 
return width;
}
public double getArea(){ 
return length*width; 
} //求面积方法

public class Area{
public static void main(String[] args){
Shape Circle=new Circle(2);
Shape Rectangle=new Rectangle(4,5);
System.out.println(Circle.getArea());
System.out.println(Rectangle.getArea());
}
}
运行结果:
G:\Area.java:2: illegal character: \65307
public double getArea();
1 error

解决方案 »

  1.   

    你的Shape不是抽象类,方法体不能省略的。
    在class Shape前面加一个abstract就可以了。
      

  2.   

    把Shape类改为下面这个就可以了
    abstract class Shape{ 
    abstract public double getArea(); 
      

  3.   

    对,你的sharp不是抽象类,所以要具体实例化`·
    加个abstart,变成抽象类·
      

  4.   

    因为Shape不是抽象类,所以里面的方法应该有方法体,把Shape类改为这个就可以了abstract public double getArea(); 
      

  5.   

    类的生命用abstract class Shape
      

  6.   

    还是不行啊
    G:\Area.java:2: illegal character: \65307
    abstract public double getArea();
    还有能不能帮我写一下用其他两中方法的程序啊
    接口、抽象类都不怎么懂~~~