Each time you use new, Java construct a NEW object and allocate memory for it. So the reference a and b point to different objects on the memory heap. The equals method in Object only returns true if and only if the two references refers to the same object. To compare the object content you have to override the method. For example, String object has its own equals method that compares the character sequence of two strings rather than if the two String references point to the same object on the heap.
Hi Luk Hann After you get yourself aquainted with the concept of object equivalence , you may take the following self evaluation questions. http://www.tipsmart.com/javacert/selfreview/objequiv.htm Understanding this concept is crucial for learning Java as well as from SCJP standpoint. -Sandeep Nachane
Hi, Sandeep, Thanks for your recommendation. The quiz is really good and I actually took the quiz before asking the questions here. I got completely confused with the operator == and method equals() after taking the quiz (plus other questions in this topic from Ablahish's Java Quiz). For example, I couldn't understand Q5 & Q10 as well as a couple of other questions in tipsmart's quiz. I really wonder what's the rule of thumb here to deal with those questions. Since I am goint to take the exam next week, and it is my pain in the neck still geting confused with it so far! Someone please help me out on this topic and I highly appreciate it! Luk
Men call me Jim. Women look past me to this tiny ad: