In the new program, did the ==
operator look at the contents of the object?
No. The ==
operator looks only at the variables.
For primitive types, also, the ==
operator looks only at the variables.
For example:
int x = 32; int y = 48; if ( x == y ) System.out.println("They are equal.");
Only the contents of the variables x
and y
are examined.
But with primitive types, the contents of a variable is the data, so with
primitive types ==
looks at data.
With reference types, ==
looks at the contents of the variables,
but now the variables contain object references.