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

Java's Set implementations rely on both equals() and hashCode() to determine uniqueness and prevent duplicates. When storing persistent objects in a Set, you must override both methods to ensure correct behavior during add/contains operations.