Question: In the Square class, override the equals method. The default equals method only returns true if the two objects are the same. For the Square

In the Square class, override the equals method. The default equals method only returns true if the two objects are the same. For the Square class, two squares should be equal if they have the same size. The equals method takes an Object as its argument. If your Object parameter is Object obj, you can cast it to a Square by using code such as: Square s = (Square) obj;. Before doing this, you should make sure that your Object is indeed a Square. To do this, you can use the instanceof keyword. Finally, you can now test the equality of the sizes of the squares.

Now in the SquareTester class from above, make two rectangles of the same size and two squares of the same size. Test the rectangles for equality using == and equals. Now do the same for the squares. Print results

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!