我有這個原始的父級抽象類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