为什么setA()方法不传变量a的时候可以修改外部类的私有变量a的值,但是传了就修改不了外部类中变量的值了?
class Outer
{
private int a = 1;
{
System.out.println("外部类~~"+"a="+a);
}
private void pri()
{
System.out.println("外部类~~"+"a="+a);
}
class Inner
{
void setA(int a )
{
a = 0;
System.out.println("外部类~~"+"a="+a);
pri();
}
}
void setIn()
{
Inner in = new Inner();
in.setA(a);
}
}
class OuterInner
{
public static void main(String[] args)
{
Outer out = new Outer();
out.setIn();
}
}
|