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