Because in this case both method() and main()have their own "sb". When you call method, its own "sb" is created and when method returns to main(), its local variables get destroyed!! Hence when you are accessing in main(), its referring to main()'s local "sb"!!
<i>If there were no Exceptions (not Errors!), Life would have kinda sucked!!</i>
To my knowledge, 'sb' in method() and main() points to the same object, when 'sb' is passed to method(). But in line, sb = new StringBuffer("Hai"); you are creating new object for 'sb' and assigning it to that. So the changes made to 'sb' in method() doesn't reflect for 'sb' in main().
However, if you comment that line and run the code you will get "String Buffer Added". because , even in method() you modify the same object using other reference.
Joined: Jan 21, 2008
Thanks Sowjanya, your right, i have compiled and checked.