成员内部类面试题--要求:使用已知的变量,在控制台输出30,20,10

成员内部类面试题--要求:使用已知的变量,在控制台输出30,20,10

class Outer {
    	public int num = 10;
    	class Inner {
    		public int num = 20;
    		public void show() {
    			int num = 30;
    			System.out.println(30);	//就近原则
    			System.out.println(this.num);	//内部类成员调用
    			System.out.println(Outer.this.num);	//不可以用super,Inner不是子类,用Outer.this.num,限定了就是外部类
    		}
    	}
    }
    class InnerClassTest {
    	public static void main(String[] args) {
    		Outer.Inner oi = new Outer().new Inner();
    		oi.show();
    	}	
    }
    结果
    30
    20
    10
原文地址:https://www.cnblogs.com/longmo666/p/14444024.html