public class EqualityDemo { public static void main(String[] args) { // create two Rectangle objects with the same parameters Rectangle r1 = new Rectangle(100, 200, 5, -5); Rectangle r2 = new Rectangle(100, 200, 5, -5); // objctes are different. We fail here. if( r1 == r2) System.out.println("r1 == r2"); // Equals function works! if(r1.equals(r2)) System.out.println("r1 equals r2"); if(r2.equals(r1)) System.out.println("r1 equals r2"); // hashCode return values are also equal. System.out.format("r1 hashCode: 0x%x\n", r1.hashCode()); System.out.format("r2 hashCode: 0x%x\n", r2.hashCode()); } }