本帖最后由 JXHIUUI 于 2015-8-15 09:43 编辑
- class Outer
- {
- static int x = 3;
-
- static class Inner
- {
- void function()
- {
- System.out.println("inner:"+x);
- }
- }
-
- void method()
- {
- Inner in = new Inner();
- in.function();
-
- }
- }
- class InnerClassDemo
- {
- public static void main(String[] args)
- {
- new Outer.Inner().function();
- }
- }
复制代码 如果内部类function功能中调用x时加this,即this.x,编译就会出错。如果Outer.this.x同样也会编译出错。初学者,求大神来解答!!
|
|