Hi Ravi,
When you pass objects as parameters to methods, java doesn't pass their references, but it passes another reference which still points to the same object. So if you have the object 'a' pointing to 100, then a is the reference and 100 is the object. Assume that 100 is stored in a memory location 0x1234. a is a reference to that memory location. Now when you send it as a parameter, then java creates one more reference which still points to the same memory location. So effectively you are having one object with two references.
If you are clear till that point, whatever change you make to the object inside the method will get reflected in the calling method. But whatever change you make to the reference just stays there. It doesn't come back to the calling method. if you call a.append(), it operates on the object. But in the second statement, you are redirecting the duplicate reference. So it is not affecting the object which is stored in the place where the reference was pointing to previously. So b has the same value.
Hope i am clear.
Thanks,
Gokul.