Multiple choice technology web technology

If you intend to put instances of persistent classes in a Set, you have to

  1. Override equals() method

  2. Override hashCode() method

  3. Both a and b

  4. Neither a nor b

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

When storing instances of persistent classes in a Java Set, you must override both equals() and hashCode() to ensure correct behavior, as sets rely on these methods to prevent duplicate elements and locate objects.