Hi Ash,
First of all, EVERY object in
Java has an equals() method, as it is defined in the Object class, and every class in java implicitly extends Object. So, StringBuffer does have a equals() method, which it inherits from Object.
Regarding the code snippet, no wonder you get no output. You are not supposed to get output according to the code given. Output is obtained only if the condition in the if statements are true.
As both if statements are evaluated to false, you don't get any output. the sb==sb1 statement evaluates to false because the two references refer to different objects, and the sb.equals(sb1) statement evaluates to false because the equals() method is not overridden in the StringBuffer, and hence the equals() from Object is called, which performs a shallow comparison(equivalent to sb==sb1).
I have made some changes in the System.out.println() statements in the code, and the output is obtained.
I hope it clears your doubt.
Prasanna.