Multiple choice general knowledge

Which of the following statements are true about the default implementation of the public int hashCode() method of the Object class?

  1. The Object class does not provide any implementation for the hashCode method; every class must override it

  2. As far as it may be practically possible, the hashCode method defined by the Object class does return distinct integers for distinct objects

  3. For two object references referring to the same object, the hashCode method returns the same integer

  4. It returns a fixed number that internally represents the Object class for the JVM

  5. Only choice D is correct

Reveal answer Fill a bubble to check yourself
B,C Correct answer
Explanation

The Object class does provide a default hashCode() implementation (not overridable as A claims). It typically converts the internal memory address to an integer, so distinct objects usually get distinct hashCodes (B is true). For references to the same object, hashCode() returns the same integer (C is true). D is false because it's not a fixed number representing the Object class itself.