Hi,
public class Test{
public static void main(
String[] args){
StringBuffer sb1 = new StringBuffer("hello");
StringBuffer sb2 = new StringBuffer("hello");
Test t = new Test();
t.Buftest(sb1,sb2);
System.out.println(sb1);//1
System.out.println(sb2);//2
}
public void Buftest(StringBuffer s1,StringBuffer s2)
{
s1.append(" there");
s2 = s1;
System.out.println("Inside the method " + s1);//3
System.out.println("Inside the method " +s2);//4
}
}
In the above program,the output of lines 3 & 4 are as expected
Inside the method hello there
Inside the method hello there
but the output of lines 1 & 2 are as follows:
hello there
hello
Could anyone explain this to me....why aren't sb1 and sb2 same?
Whats happening?
Thanks,
Rashmi