class ColorPoint extends Point { int color; ColorPoint(int x, int y, int color) { super(x, y); this.color = color; } public boolean equals(Object o) { if (o instanceof ColorPoint) { if (!o.getClass().isAssignableFrom(getClass())) { //let the subclass decide if we are equal return o.equals(this); } ColorPoint cp = (ColorPoint)o; return color == cp.color && super.equals(o); } return false; } public int hashCode() { return x*31 + y*29 + color*37; } public String toString() { return ("ColorPoint: x = " + x + ", y = " + y + ", color = " + color); } }