Hello Watson Li,
The answer to your question is based on what do you use to do comparison i.e equals() method or == operator and whether equals() method has been overriden in your class or no.
Consider two objects, x and y. If you use == to compare these objects, then what you are essentially doing is comparing the references (or the memory addresses) which point to this objects. This will work fine for you if you want to ensure both references point to the same object (only then the memory addresses will be same, right !!). But if want to check whether the two objects x and y are alike or are equal to each other content wise, then you need to use "equals()". But, remember this !!! "equals()" method is defined in Object class and as per the
Java API for Object class "The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true)" which means Object class method equals() just uses == comparison . So, if you are looking to check if two objects are exactly alike then you need to override this method in your class, like the "equals()" method in String class which overrides Objects "equal()" method.
I have set of 15 questions on my homepages which deals only with object equivalence fundamentals. You may find it useful..
The url is
http://www.tipsmart.com/javacert/selfreview/objequiv.htm Sandeep Nachane