If two objects are equals(), then their hashCode() must be the same.

If you override equals(), you should override hashCode(), however it is not necessary to override equals() if we override hashCode().

Joshua Bloch says on Effective Java

You must override hashCode() in every class that overrides equals(). Failure to do so will result in a violation of the general contract for Object.hashCode(), which will prevent your class from functioning properly in conjunction with all hash-based collections, including HashMap, HashSet, and Hashtable.