What is not true of .hashCode() in Java?

  • A: there is a default .hashCode() for any Object
  • B: returns an int
  • C: must be the same for objects that are .equals()
  • D: could be negative
  • E: is usually a prime

    Answer: E

    We often use a prime number as the size of a hash table and compute the hash value modulo that prime. The .hashCode(), though, is any int and usually will not be a prime.

    Contents    Page-10    Prev    Next    Page+10    Index