 Once again, here's a class that creates an object that represents a rectangle. And here's a program that defines three rectangles, two of which have the same width and height, and one of them that has a different width and height. We want to compare these rectangles for equality. Just as with strings, when you want to compare objects, you need to use the equals method. Let's compile this program and run it. It's no surprise that R1 and R2 aren't equal, but it is a surprise that R2 and R3 are also not considered to be equal. What's going on here? The source of the problem is that the default equals method compares the objects for their memory locations, not the values in their fields. Let's comment out our custom-made two-string method so that we can get the default two-string method that returns the memory addresses of objects. And recompile. And here, let's add some code to show the memory addresses of our three rectangles. Let's compile that. And as you see, they all have different addresses in memory, and that's why R2 dot equals R3 comes back as false. In order to fix this problem, just as we had to write our own version of two-string to overwrite its default action of giving us a memory address, we also have to create our own equals method to override the default action of comparing the memory addresses. Here's what our method will look like. It's going to be a Boolean method called equals, and its parameter will be another rectangle that we want to compare this rectangle to. In the body of the method, we'll create a Boolean variable for our result and set it to an expression that does the comparison. We want to see if the width of this rectangle that's calling equals is the same as the other rectangle's width and the height of this rectangle that's making the call is the same as the other rectangle's height. We'll return that result. The keyword this means the instance that's calling the method. Let's recompile. Come back to our test program and recompile it and run it. And now we get the answers we want because equals is comparing the fields, not the memory addresses. The moral of the story, if you want to compare your own objects for equality, you'll have to override the default equals method by providing one of your own.