***SCJP的一道题(NO.1)***
public class Foo{
public static void main(String[] args){
StringBuffer a = new StringBuffer("A");
StringBuffer b = new StringBuffer("B");
operate(a,b);
System.out.println(a + "." + b);
}
static void operate(StringBuffer x, StringBuffer y){
x.append(y);
y = x;
}
}
What is the result?
A. The code compiles and prints "A.B".
B. The code compiles and prints "A.A".
C. The code compiles and prints "B.B".
D. The code compiles and prints "AB.B".
E. The code compiles and prints "AB.AB".
正确答案为D
问题是:
我怎么觉得应该是E,
因为当对象a与b传入operate时,执行x.append(y)后,x变为AB,也就是a也变为AB了此后把x赋给了y,当然y也是AB,那么b也应该变为AB(但正确答案的意思,好像没有发生变化)所以答案应为E呀?
不明白,请解释一下,谢谢!