You should know the methods that are common to all classes, those that are in the java.lang.Object clone, equals, finalize, getClass, hashCode, notify and notifyAll, toString, and the 3 wait(...)
What you said is true, but the versions of toString() and equals() inherited from Object are usually not the ones you want.
Object.toString() would not give you the characters in the StringBuffer, but StringBuffer overrides that toString() with a version that does.
On the other hand, Object.equals() is not overridden in StringBuffer, so comparing two StringBuffer objects with equals() tests for the same object, like ==, rather than comparing the characters in the two StringBuffer objects.
Amit- The equals() methods is a special method that is implemented in the base of all classes (Object class), this method (if not overridden in a subclass) has the same effect of the == operator which tests whether two references point to the same object.
Some classes, like the String class override this method to achieve the functionality of actually comparing the "value" of String objects instead of just comparing references. However, StringBuffer class doesn't override this method, therefore when you call equals() method on a StringBuffer class you are actually calling the equals() method in the Object class which compares references.
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!