// create a rectangle with top-left coordinate at (10, 20) and with width 50 and height 30 Rectangle rect = new Rectangle(10, 20, 50, 30);
// create two rectangles Rectangle rect1 = new Rectangle(10, 20, 50, 30); Rectangle rect2 = new Rectangle(40, 50, 30, 20); // check if they intersect if (rect1.intersects(rect2)) { System.out.println("The rectangles intersect."); } else { System.out.println("The rectangles do not intersect."); }This code creates two Rectangle objects and checks if they intersect using the intersects() method. If they do intersect, it prints a message accordingly. Package Library: The java.awt.Rectangle class is part of the Java Abstract Window Toolkit (AWT) package library.