关于成员内部类的一个测试

demo如下:

public class TestInner {

    private int x;

    public static void main(String[] args) {
        TestInner.Inner a = new TestInner().new Inner();
        a.doit(2);
    }

    public class Inner {
        private int x = 9;

        public void doit(int x) {
            x++;
            System.out.println(x);
            this.x++;
            System.out.println(this.x);
            TestInner.this.x++;
            System.out.println(TestInner.this.x);
        }
    }

}

可以测试下结果为:

3
10
1

其中第一个x调用的是形参x,

第二个x调用的是内部类的变量x,

第三个调用的是外部类的变量x

Ride the wave as long as it will take you.
原文地址:https://www.cnblogs.com/jianpanaq/p/7761137.html