Question OOP-CLS-0067
HardTwo objects of a class compare equal with == in Java but are different objects. What must the class do for HashSet to treat them as the same element?
- A.
Override only equals()
- B.
Override both equals() and hashCode() consistently
- C.
Make all fields public
- D.
Override only toString()
Sign up free to see the answer and a step-by-step explanation.