我有这个原始的父级抽象类Geometric,我在Octagon中扩展它,并且还实现了Comparable和Cloneable。 IDK为什么我不断收到上述错误。请大家谅解。“必须实现继承的抽象方法”
class Octagon extends GeometricObject implements Cloneable, Comparable{
private double side;
public class Octagon(){
}
public class Octagon(double s){
side=s;
}
public double getArea(){
return (2+4/Math.sqrt(2))*side*side;
}
public double getPerimeter(){
return 8*side;
}
public int compareTo(Object o){
if (getArea()>((Octagon)o).getArea()){
return 1;
}
else if (getArea()<((Octagon)o).getArea()){
return -1;
}
else
return 0;
}
public Object clone() throws CloneNotSupportedException{
super.clone();
}
}
这是我的几何级
public abstract class GeometricObject{
private String color="white";
private boolean filled;
private java.util.Date dateCreated;
protected GeometricObject(){
dateCreated=new java.util.Date();
}
protected GeometricObject(String color, boolean filled){
dateCreated=new java.util.Date();
this.color=color;
this.filled=filled;
}
public String getColor(){
return color;
}
public void setColor(String color){
this.color=color;
}
public boolean isFilled(){
return filled;
}
public void setFilled(boolean filled){
this.filled=filled;
}
public java.util.Date getDateCreated(){
return dateCreated;
}
public String toString() {
return "created on "+dateCreated+"\ncolor: "+color;
}
public abstract double getArea();
public abstract double getPerimeter();
}
最可能的是,你忘了实现你的父类的抽象方法之一'GeometricObject'。 – vidit 2012-03-20 05:00:53
听起来好像在'GeometricObject'中有一些抽象方法,你不会覆盖。编译器应该告诉你,你错过了哪个方法,哪个应该回答你的问题。 – 2012-03-20 05:00:57
除非您发布该抽象类的代码,否则我们不能告诉您为什么发生错误。 – asgs 2012-03-20 05:01:25