This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
When you enter in the method "method", there is only 1 object in memory (the one with the value "StringBuffer") but 2 references to this object (sb in the main andthe local variable sb in the method parameter).
Ref sb (from main method) ---> "StringBuffer" Ref sb (from method method) ---> the same object
So when you call sb.append(...) in the method "method", it's the original object that is modified =>StringBufferAppend. At this time we have in memory:
Ref sb (from main method) ---> "StringBufferAppend" Ref sb (from method method) ---> the same object
Then when you create a new object and assign it to sb, it is the local reference that is modified, not the reference from the variable of the main method. The result in memory is: