我有一个抽象类GeometricObject,它由一个基类Rectangle扩展。在超类中,我提供了两个构造函数:
public abstract class GeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
/** Construct a default geometric object */
protected GeometricObject() {
dateCreated = new java.util.Date();
}
/** Construct a geometric object with color and filled value */
protected GeometricObject(String color, boolean filled) {
dateCreated = new java.util.Date();
this.color = color;
this.filled = filled;
}
在矩形类中,我创建了另一个构造函数,它应该调用GeometricObject参数构造函数。如果我错了,请纠正我,但这是为" color"提供价值的正确方法。和"填充"对于Rectangle对象。
public class Rectangle extends GeometricObject implements Comparable<Rectangle>{
private double width;
private double height;
public Rectangle() {
}
**public Rectangle(double width, double height, String color, boolean filled) {
super(color, filled);
this.width = width;
this.height = height;
}**
但是,Eclipse在super(color,filled)语句旁边给出了以下错误: &#34;构造函数GeometricObject(String,boolean)未定义&#34;
我错过了什么?
答案 0 :(得分:0)
构造函数调用看起来很好,我在Eclipse中尝试过,它编译时没有任何错误。但是,当Rectangle类实现Comparable时,我们需要覆盖compareTo
方法,如下所示:
@Override
public int compareTo(Rectangle o) {
// TODO Auto-generated method stub
return 0; //should be replaced by comparison logic
}