【发布时间】:2012-03-20 04:58:32
【问题描述】:
我有这个原始的父抽象类 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中实现抽象方法之一。 -
听起来
GeometricObject中可能有一些您没有覆盖的抽象方法。编译器应该准确地告诉你你缺少哪个方法,哪个应该回答你的问题。 -
除非您发布该抽象类的代码,否则我们无法告诉您错误发生的原因。
-
显示几何对象的代码。
-
最好使用好的IDE(eclipse/intellij/netbeans)..这样可以避免一些小错误。
标签: java