给出以下代码:
package core;
public abstract class GeometricElement {
private float area;
public abstract void calculateArea( ); //will be implemented in subclasses
public float getArea( )
{
this.calculateArea( );
return area;
}
}
package core;
public class abstract PerfectPolygon extends GeometricElement
{
public abstract void calculateArea( );
private float length;
private int sides;
public float getRadius() { return this.length; }
public float getSides() { return this.sides; }
public void setRadius(float newLength) {this.length = newLength;}
public void setSides(float newSides) {this.length = newSides;}
}
package core;
public class PerfectTriangle extends PerfectPolygon {
PerfectTriangle() {}
public void calculateArea( ) { }
}
package core;
public class Square extends PerfectPolygon {
Square() {}
public void calculateArea( ) {}
}
包核心;
public class Circle extends GeometricElement
{
private float radius;
Circle() {}
public float getRadius() { return this.radius; }
public void setRadius(float newRadius) {this.radius = newRadius;}
public void calculateArea( ) {}
}
我正处于项目的开始阶段,但是,由于Eclipse抛出了以下错误,我似乎无法继续: 1)“在PerfectPolygon类中,令牌上的语法错误”abstract“,删除此令牌” 2)在Square类中“PerfectPolygon无法解析为类型” 3)在PerfectTriangle类
中,“PerfectPolygon无法解析为类型”请注意我几乎没有编写任何代码,我只是开始编写代码,但是 由于某种原因,Eclipse不会允许编译这些代码。 知道为什么吗? 我很感激你的帮助
此致 罗恩
答案 0 :(得分:4)
abstract class
而不是
class abstract
答案 1 :(得分:3)
该课程应为:
public abstract class PerfectPolygon extends GeometricElement { ...
就像你的其他抽象类一样,编译。