Home > DeveloperSection > Interviews > Why we override equals() method?

Posted on    May-13-2015 11:24 PM

 Java Java  Collection 
Ratings:
 1 Answer(s)
  436  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Points:4035
Posted on    May-13-2015 11:24 PM

The equals method is used to check whether two objects are same or not. It needs to be overridden if we want to check the objects based on property.

For example, Employee is a class that has 3 data members: id, name and salary. But, we want to check the equality of employee object on the basis of salary. Then, we need to override the equals() method.



Don't want to miss updates? Please click the below button!

Follow MindStick