Hi can anyone explain this?
For the code given below answer is D.
I am confused!
contents of stringBuffer are mutable.In that case
in line 10 b is assigned the value of a so it should be one more,how come it is two?
Thanks.
public class
Test {//line1
public static void main(
String args[]) {//line2
StringBuffer a = new StringBuffer("One");//line3
StringBuffer b = new StringBuffer("Two");//line4
Test.swap(a,b);//line5
System.out.println("a is "+ a +"\nb is " + b);//line5
}//line7
static void swap (StringBuffer a, StringBuffer b) {//line8
a.append(" more");//line9
b=a;//line10
}
}
What will be the output?
Answer:
a. a is One
b is Two
b. a is One
b is One
c. a is One more
b is One more
d. a is One more
b is Two
e. a is One more
b is Two more