In Java, if object A contains same the same data of object B, are they equal?

Search Interview Questions

 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text


Interview Questions and Answers

 Q1. In Java, if object A contains same the same data of object B, are they equal?Core Java
Ans. it depends on the implementation of equals method of the respective class. If no definition is provided and it uses the default definition of the object class, two references are equal only if they point to the same object.

We can have such an equality defined for a particular class objects if we provide appropriate implementation of equals method comparing all those fields.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     equals  equals method

Related Questions

  Difference between == and .equals() ?
  Which String class does not override the equals() and hashCode() methods, inheriting them directly from class Object?
  Can we compare Integers by using equals() in Java ?
 Write a class and override the equals and hashcode method ?
 What is equals method in Java ?
 What is a reflexive equals contract ?
 Explain Transitive equals contract.
 why is "".equals(str); safer than str.equals("")?
 Difference between equals and compareTo in Java ?

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: