This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Question: Which of these statements are true? A. If the references x and y denote two different objects, then the experssion x.equals(y) is always false. B. All array objects have a method named clone. Answer is B only. Why isn't answer A. true??? Thanks
x.equals(y); could be false because the equals() method tests the value of the object not the reference. however, i don't think it would always be false, because if both objects have the same values then it would be true.
Bob, The equals method is defined in the Object class and it does nothing but basic reference comparison. Several subclasses of Object override the equals method to do content based comparison. The examples are the wrapper classes and the String class. However, there are some derivatives of Object that doesnot override the equals method. One such class is the StringBuffer. If a class (derived from Object ) does not override the equalsmethod, then as per the OO rules, calling equals method on an instance of such a class will call the Object.equals() method.... and you know what happens Hence the answer A is false! Hope that helps, Ajith [This message has been edited by Ajith Kallambella (edited October 10, 2000).]
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).