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

谁帮我解决一个问题。小女感激不尽~~~
在这个程序中定义了一个外抽象类Shape。再定义两个shape类的子类Rectangle和Circle类,在子类中实现父类的抽象方法。
但是运行的时候出错。出错提示:CMD中运行提示错误:第5行和第20说Rectangle和Circle不是抽象的类,并且没有覆盖Shape中的抽象方法。麻烦大家帮我看看我哪个地方代码写的不对?我不知道该怎么改,我刚学JAVA,才学到抽象类这各部分的内容,希望能在我代码的基础上改,修改不要太大,至少改的我能看懂。
abstract class Shape{
public abstract int getArea();//定义一个返回整型的抽象方法getArea
public abstract void printArea();//定义一个没有返回值的抽象方法printArea
}
class Rectangle extends Shape{
int width;
int length;
public Rectangle(int width,int length){
this.width = width;
this.length = length;
}
public int getArea(){
return width*length;
}//实现父类的抽象方法getArea,返回width*length的值
public void printAera(){
System.out.print("我是一个矩形,我的面积是"+getArea());
}
}//实现父类的抽象方法printAera,在屏幕上现实矩形的面积

class Circle extends Shape{
int radius;
public Circle(int radius){
this.radius = radius;
}
public int getArea(){
return radius*radius;
}
public void printAera(){
System.out.print("我是一个圆形,我的面积是"+getArea());
}
}
public class MyAbstract{
public static void main(String[] args){
Rectangle r=new Rectangle(3,4);
Circle c=new Circle(2);
r.printArea();
c.printArea();

}

}

------解决方案--------------------
父类中:
Java code
public abstract void printArea()