import java.awt.Color; class Point { private final int x, y; public Point(int x, int y) { this.x = x; this.y = y; } public boolean equals(Object o) { if (!(o instanceof Point)) return false; Point p = (Point)o; return this.x == p.x && this.y == p.y; } } // class Point class ColorPoint { final private Point point; final private Color color; public ColorPoint(int x, int y, Color color) { point = new Point(x, y); this.color = color; } public Point asPoint() { return point; } public boolean equals(Object o) { if (!(o instanceof ColorPoint)) return false; ColorPoint cp = (ColorPoint)o; return this.point.equals(cp.point) && this.color == cp.color; } } // class ColorPoint public class TransitivityExample4 { public static void main(String[] args) throws SimpleSetFullException { ColorPoint cp1 = new ColorPoint(1, 2, Color.RED); ColorPoint cp2 = new ColorPoint(1, 2, Color.RED); ColorPoint cp3 = new ColorPoint(1, 2, Color.BLUE); ColorPoint cp4 = new ColorPoint(3, 3, Color.GREEN); System.out.println("cp1.equals(cp2): " + cp1.equals(cp2)); // true System.out.println("cp1.equals(cp3): " + cp1.equals(cp3)); // false System.out.println("cp1.equals(cp4): " + cp1.equals(cp4)); // false Point p1 = new Point(1, 2); System.out.println("cp1.equals(p1): " + cp1.equals(p1)); // false! System.out.println("p1.equals(cp1): " + p1.equals(cp1)); // false! System.out.println("cp1.equals(p1): " + cp1.equals(p1)); // false! System.out.println("p1.equals(cp3): " + p1.equals(cp3)); // false! System.out.println("cp1.equals(cp3): " + cp1.equals(cp3)); // false! } // main } // class TransitivityExample4