package homework;
public class Chenge{
static class Mytest{
public int num;
}
public static void swp(Mytest a, Mytest b){
int tmp = a.num;
a.num = b.num;
b.num = tmp;
}
public static void main(String[] args) {
Mytest mytest1 = new Mytest();
Mytest mytest2 = new Mytest();
mytest1.num = 10;
mytest2.num = 20;
System.out.println("mytest1.num="+mytest1.num+"mytest2.num="+mytest2.num);
swp(mytest1 ,mytest2);
System.out.println("mytest1.num="+mytest1.num+"mytest2.num="+mytest2.num);
}
}
重点在于传入swp函数中的是一个类,并且改变成员数据的值!