public class TestBuffer {
public void myBuf( StringBuffer s, StringBuffer s1) {
s.append(" how are you") ;
s = s1;
}
public static void main (
String args[] ) {
TestBuffer tb = new TestBuffer();
StringBuffer s = new StringBuffer("Hello");
StringBuffer s1 = new StringBuffer("doing");
tb.myBuf(s, s1);
System.out.print(s);
}
}
The answer is "Hello how are you". My question is that since the references of s and s1 have been passed to the method myBuff, why wouldn't s refer to where s1 is refering after the statement s=s1?
Thanks.