I am new to java technology, and may be it is a simple problem but I am confused like anything. I know that there is no concept of call by reference in java. It only uses call by value i.e. passing copy to another method
Kindly check the output of below code
public class Test {
public static void main(String[] args) {
StringBuffer a = new StringBuffer ("A");
StringBuffer b = new StringBuffer ("B");
System.out.println("Before Operate"+a + "," +b);
operate (a,b);
System.out.println(a + "," +b);
}
static void operate (StringBuffer x, StringBuffer y) {
x.append(y);
y = x.append("C");
y.append("D");
}
}
output of above code is :ABCD , B (Second Syso)
i am not sure why this is appending everything in a not in b. I googled a lot but it only create confusion.So it would be great help if some one elaborate it completely.
Thanks in advance
P.S:-If this is already been asked at this forum kindly provide me a link,as i was not able to find it.