Check equality and hash-code compatibility

A Java program compares shipment identifiers using a class that obeys the standard equals and hashCode contracts. A hash code is the integer returned by an object's hashCode() method.


Each row describes an independent proposed result for two non-null objects, a and b. No relevant object state changes during a comparison. Enter permitted if the combination can satisfy the contracts, or forbidden if it violates them. Judge contractual possibility rather than the behavior of any particular implementation.

Proposed resulta.hashCode()b.hashCode()Permitted or forbidden
a.equals(b) returns true3737
a.equals(b) returns true3782
a.equals(b) returns false5454
a.equals(b) returns false5491

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Object Equality Questions: