題目是這樣。
public class T_Three {
public void increment(int a, Integer b, String c, StringBuffer d) {
a++;
b++;
c = c + " world";
d.append(" world");
}
public static void main(String[] args) {
int a = 0;
Integer b = new Integer(0);
String c = "hello";
StringBuffer d = new StringBuffer("hello");
new T_Three().increment(a, b, c, d);
System.out.println("a=" + a + " b=" + b + " c=" + c + " d=" + d);
}
}
問輸出的結果a=? b=? c=? d=?
然后我在IDE上試了一下。輸出的結果是:
a=0 b=0 c=hello d=hello world
請問是為什么呢?為什么a和b的自增沒有增加?為什么String沒有拼接,為什么StringBuffer的append卻起了作用?
Stringbuffer我個人理解是append操作的就是傳進來的對象,所以對其起了作用。c沒有拼接是因為操作的是函數自身的c,并不影響外面的c??墒荌nteger和int我就不太懂了。
不知道我理解對不對,希望各位指導一下。
添加回答
舉報
0/150
提交
取消