public class ArgumentTest {
// 静态内部类
static class IntA{
private int a;
public IntA(int a){
this.a=a;
}
public int getA(){
return a;
}
public void setA(int a){
this.a=a;
}
}
// 改
static public void change(int a){
a=3;
}
//
static public void change(IntA a){
a.setA(3);//3
}
//a1传过来
static public void changeRef(IntA a){
a=new IntA(9);
}
public static void main(String[] args){
int a=2;
change(a);
System.out.println(a);//2
IntA a1 = new IntA(5);
change(a1);
System.out.println(a1.getA());
// 改变引用
changeRef(a1);
System.out.println(a1.getA());
}
}
输出答案:233
以下的图可做参考