Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


For object reference comparison, which operators are used?

  1. == and !=

  2. equals() and !equals()

  3. hashCode() and !hashCode()

  4. == and ===

The correct answer is: == and !=

Certain operators like the == and != do not compare the contents of objects, but rather the memory reference/address. This means these operators simply check if the objects being compared are the same object, not if they have the same content. The equals() and !equals() methods are used for content comparison, but these are not operators. The hashCode() and !hashCode() methods simply return unique hash codes for objects, they do not compare objects. The === operator is not a valid Java operator. Therefore, the correct answer is A as it correctly identifies the operators used for object reference comparison.