Rectangle rect1 = new Rectangle(10, 20, 30, 40); Rectangle rect2 = new Rectangle(10, 20, 30, 40); if(rect1.equals(rect2)) { System.out.println("rect1 and rect2 are equal"); }
Rectangle rect1 = new Rectangle(10, 20, 30, 40); Rectangle rect2 = new Rectangle(20, 30, 40, 10); if(!rect1.equals(rect2)) { System.out.println("rect1 and rect2 are not equal"); }This example creates two rectangles with different coordinates and dimensions, and then checks if they are not equal using the equals() method. The output is "rect1 and rect2 are not equal". Both examples use the java.awt package library, which is a part of the Java Standard Edition (Java SE) platform.