In the EqualsTest class, you inherit the equals methods from Object.java. The method that's defined there only checks references. If you want to compare two objects from a class that you define, you need to override equals and put your own definition of what it means for two objects of your type to be equal.
the equals() method does whatever you tell it to do. it could, conceivably, do just about anything.
Because it is such an important method, the grand-daddy Object class has one defined. Every class, since they all derive from Object, automagically gets a copy of its equals() method, including your EqualsTest class. you get it free, without doing anything!!!
now, unfortunatly, the way it's defined in the Object class is to compare references. because really, there is no other default implementation that would work for any possible class that would ever be written by someone.
so, if you create your own class, and want equals() to make sense, you must override it and define it how you want it to work. many of the existing classes, such as String or Int, have already done this for you.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
The equals() method will compare object references, unless it is overwridden, I think. For String literals, it will compare values (because it has been overwridden), while for wrapper classes, it will compare the values of their primitive values (because it has been overwridden as well).
If you are overriding equals(), also try to override hashCode() method. If to objects are equals, then their hashcodes should also be equal. However unequal objects need not produce distinct hash codes.
A 16:You should override the equals() and hashCode() methods from the Object class. The default implementation of the equals() and hashcode(), which are inherited from the java.lang.Object uses an object instance�s memory location (e.g. MyObject@6c60f2ea). This can cause problems when two instances of the car objects have the same colour but the inherited equals() will return false because it uses the memory location, which is different for the two instances. Also the toString() method can be overridden to provide a proper string representation of your object. Points to consider:
--If a class overrides equals(), it must override hashCode(). --If 2 objects are equal, then their hashCode values must be equal as well. --If a field is not used in equals(), then it must not be used in hashCode(). --If it is accessed often, hashCode() is a candidate for caching to enhance performance.