试试这个
public class Outer1 {
private int index = 100;
class Inner {
private int index = 50;
void print() {
int index = 30;
System.out.println(index);// 30
System.out.println(this.index);// 50
System.out.println(Outer1.this.index);// 100
}
}
Inner getInner() {
return new Inner();// 返回一个内部类的引用
}
}
class Test1 {
public static void main(String[] args) {
Outer1 outer1 = new Outer1();
Outer1.Inner inner = outer1.getInner();
inner.print();
}
}