黑马程序员技术交流社区

标题: 。。。。。出道题做做。。。。。。。 [打印本页]

作者: 班志国    时间: 2012-11-3 17:33
标题: 。。。。。出道题做做。。。。。。。

  1. class Outer{
  2.         int x = 6;
  3.         class Inner{
  4.                 int x = 7;
  5.                 void met(){
  6.                         int x = 4;
  7.                         System.out.println(Outer.this.x);
  8.                         System.out.println(this.x);
  9.                         System.out.println(x);
  10.                 }
  11.         }
  12.         public static void main(String[] args){
  13.                 Outer.Inner in = new Outer().new Inner();
  14.                 in.met();
  15.         }

  16. }
  17. 打印结果是多少
复制代码

作者: 王亚运    时间: 2012-11-3 17:48
6 //内部类对象调用外部类变量
7//内部类对象调用内部类变量
4//内部类对象调用方法局部变量

刚才还试了试 改成
static  int x = 6;
然后,this 就可以省略了。。
话说对内部类很头疼,领教了。
{:soso__6468533990763016983_4:}





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2