class Outer
{
int outer_i =100;
void test()
{
Inner in=new Inner(this);
in.display();
}
public static void main(String [] args)
{
Outer outer=new Outer();
outer.test();
}
}
class Inner
{
Outer outer;
public Inner(Outer outer)
{
this.outer=outer;
}
void display()
{
System.out.println("outer_i="+outer.outer_i);
}
}
等价于
class Outer
{
int outer_i =100;
void test()
{
Inner in=new Inner();
in.display();
}
class Inner
{
void display()
{
System.out.println("outer_i="+outer_i);
}
}
public static void main(String [] args)
{
Outer outer=new Outer();
outer.test();
}
}