199k views
4 votes
When we use the equality operator (==) when comparing objects, are we comparing the references?

1) True
2) False

1 Answer

6 votes

Final answer:

Using the equality operator (==) when comparing objects indeed compares the references, not the content of the objects. Two distinct objects with identical content will be considered not equal if their references are different.

Step-by-step explanation:

When we use the equality operator (==) when comparing objects, the statement that we are comparing the references is true.

This is because in programming languages like Java, the == operator checks whether the references pointing to the objects are the same, not whether the content of the objects is identical.

For example, two different objects with the same content would return false when compared with the == operator because their references are different.

User Navid Abutorab
by
8.0k points