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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started