67,513
社区成员
发帖
与我相关
我的任务
分享
import java.io.Serializable;
public class A implements Cloneable, Serializable{
public int number;
protected Object clone() throws CloneNotSupportedException{
return super.clone();
}
}
public class TempTest {
private void test1(A a) {
a.number = 5;
System.out.print(" " + a.number);
}
private void swap(A a, A b) {
A temp = a;
a = b;
b = temp;
System.out.println(" " + a.number);
System.out.println(" " + b.number);
}
public static void main(String[] args) throws Exception {
TempTest test = new TempTest();
A a = new A();
a.number = 3;
A b = new A();
b.number = 4;
test.swap(a, b);
System.out.println(" " + a.number);
System.out.println(" " + b.number);
test.test1(a);
System.out.println(" " + a.number);
A c = (A) a.clone();
test.test1(c);
System.out.println(" " + a.number);
}
}