Hi,
Your code explains the same fact that java uses pass by value. When you pass an object reference variable, you pass a copy of the bits contained in that variable, which actually is a way to point to that object. And when you pass that reference to a method, the reference becomes local to the method and its scope is limited to method. So when you reassign it, the reference changes, that is, Object to which the variable refers, changes.
In java,
String objects are given special treatement. They don't behave like other object because of their immutability. That is, String objects, once formed are immutable. In your example, this property of Strings doesn't let you alter the object.
You can try it using a StrinBuffer.
Try something like this:
You will notice that, when in the called method, we change the reference, then there is no change in the value of original object. But as we pass the reference, we can always change the original object.
This, though, is not true in case of Strings.
Sid
[ May 15, 2007: Message edited by: Sidd Kulk ]