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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 吕晓阳 中级黑马   /  2015-4-17 09:18  /  722 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

x输出结果为多少,为什么
  1. class Outer
  2. {
  3.         private int x = 3;

  4.        
  5.         class Inner//内部类
  6.         {
  7.                 int x = 4;
  8.                 void function()
  9.                 {
  10.                         int x = 6;
  11.                         System.out.println(Outer.this.x);
  12.                         System.out.println(this.x);
  13.                         System.out.println(+x);
  14.                 }
  15.         }
  16.         void method()
  17.         {
  18.                 Inner in = new Inner();
  19.                 in.function();
  20.         }
  21. }
  22. class  InnerClassDemo
  23. {
  24.         public static void main(String[] args)
  25.         {
  26.                 Outer out = new Outer();
  27.                 out.method();
  28.         }
  29. }
复制代码



1 个回复

倒序浏览
System.out.println(Outer.this.x);外部类的成员3
System.out.println(this.x);内部类的成员4
System.out.println(+x);局部变量6
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马