It depends on the class definition. If a class definition doesn't override the equals(Object) method from Object.java, then it inherits the equals(Object) method from Object.java. That method simply tests whether the references refer to the same object.
obj1 and obj2 may be referenced by the same type of object reference variable, but they might be different types of objects. If equals() was overriden properly, sometimes obj1 and obj2 are of different classes:
Hi, the above posts describe exactly what is happening behind the scenes. So the best way to check the equality of your custom objects is to override the .equals() method of the Object class and define the way in which you think that your objects/ object contents are equal.
If you open the class Object.java (inside src.zip of your jdk folder) which is superclass of all class, you will find the implementation of equals method and its like
So you can clearly see that the default implementation (in case you don�t define equals method in your class) is object reference equality and not value equality. If you want to have equals method work in your Object, you must override the implementation in your object. You can refer what they have done in String.java
So based on what your object it and how you want to define your equality, you must override the method in your class
You have apparently missed our Naming Policy on the way in. We require a real first name, followed by a space, and a last name. Please follow that link, read the page, and find the link there on how to correct your screen name. This policy is mandatory.
I would have contacted you privatly, but you did not register with an email.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors