in:
public static void swap(StringBuffer strB1,StringBuffer strB2)
{
StringBuffer strBTemp;
strBTemp=strB1;
strB1=strB2;
strB2=strBTemp;
}
just the object reference pass to the swap,like a point in c and c++,
the strB1 and strB2 only the point point to the object in heap, so,if
you type strB2=strB1,just to say the two point refer to the some place
in heap,so the output of the program is aaaaaaaa
and the second swap use a object reference pass to a submethod,
and use the method of that reference,it is just the oop thinking.so
that is right,cool.
public void change( A param ){位置一
param = you value//在这里param和上面括号里面(位置一)的param已经不是同一个了。这个param是一个类似param_1得咚咚,是虚拟机自动转换的,你改变不了你传进来的那个值。所以java号称是传值的,java里面是没有传引用这种说法的。
但是不管是位置一的param还是方法里面的这个param(相当于位置一param副本),他们指向的都是同一块内存空间,所以下面的语句是可行的
param.b = you value//这里b的值是可以被你改变的
}