More about Objects and Classes

The relational operations on primitive data are ==, >=, <=, >, <, and !=. They compare two data values, when those values' type has an ordering. For example, integers are ordered by size or magnitude. The result of a relational operation is a boolean value: either True or False. The relational operators on objects like Strings are different, and they are expressed as methods. Pay special attention to the equality method, equals().

17. Different Objects, Equivalent Data


The two objects contain the same data: java.awt.Point[x=7,y=99]

Different Objects, Equivalent Data


The picture shows the situation. There are two distinct objects (each constructed out of different bytes of memory).

The equals() method returns true because the data is equivalent.

Question 17:

Would the == operator do the same as the equals() method?