A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 廿乙木 中级黑马   /  2014-8-21 15:06  /  643 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. /*
  2. 内部类也可以定义在外部类的局部位置上,如方法中
  3. 但是不能被成员修饰符修饰。
  4. 如果内部类定义在局部,只能访问被final修饰的局部变量

  5. */

  6. class outer_11_3
  7. {
  8.         int num = 3;//定义成员变量
  9.         void method()
  10.         {
  11.                 int x =5;//定义局部变量?????????
  12.                 final int  xx = 12;
  13.                 class inner_11_3
  14.                 {
  15.                         void show()
  16.                         {
  17.                                 System.out.println("x="+x);//????????
  18.                                 //???毕老师说内部类定义在局部时,只能访问被final修饰的局部变量,
  19.                                 //???为什么我的不出错呢,还能通过编译
  20.                                 System.out.println("num="+num);
  21.                                 System.out.println("xx="+xx);
  22.                         }

  23.                 }
  24.        
  25.                 new inner_11_3().show();
  26.         }
  27. }
  28. class neibuleiDemo_11_3
  29. {
  30.         public static void main(String[] args)
  31.         {
  32.                 outer_11_3 out = new outer_11_3();
  33.                 out.method();
  34.         }
  35. }
  36. 为什么我的不出错呢???
复制代码

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马