---
title: "Why we override equals() method?"  
description: "Why we override equals() method?"  
author: "Anonymous User"  
published: 2015-05-13  
updated: 2020-09-22  
canonical: https://www.mindstick.com/interview/2524/why-we-override-equals-method  
category: "java"  
tags: ["java", "collection"]  
reading_time: 1 minute  

---

# Why we override equals() method?

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.

\

## Answers

### Answer by Anonymous User

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.

\


---

Original Source: https://www.mindstick.com/interview/2524/why-we-override-equals-method

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
