Rectangle rect = new Rectangle(10, 20, 50, 30);
rect.setSize(70, 50);
Rectangle rect1 = new Rectangle(10, 20, 50, 30); Rectangle rect2 = new Rectangle(20, 30, 40, 20); if(rect1.intersects(rect2)) { System.out.println("Rectangles intersect!"); }This checks if the two rectangle objects intersect and prints a message if they do. The java.awt.Rectangle class is a part of the java.awt package.