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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 泛大陆 中级黑马   /  2015-7-28 08:54  /  431 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

6、 在打印语句中如何打印这3个x变量?
                 class A {
                int x = 1;
                class B {
                int x = 2;
                void func() {
                int x = 3;
                System.out.println( ? );
                        }
                    }
                }
  1. public class Test6 {
  2.         public static void main(String[] args) {
  3.                 A.B b=new A().new B();//建立class B对象
  4.                 b.func();//通过class B对象调用其方法
  5.         }
  6. }
  7. class A
  8. {
  9.         int x = 1;
  10.         class B
  11.         {
  12.                 int x = 2;
  13.                 void func()
  14.                 {
  15.                         int x = 3;
  16.                         System.out.println("func方法中的变量x"+x);
  17.                         System.out.println("class B中的成员变量x"+this.x);
  18.                         System.out.println("class A中的成员变量x"+A.this.x);
  19.             }
  20.         }
  21. }
复制代码

3 个回复

倒序浏览
阔以~~~~
回复 使用道具 举报
?这个怎么了,?
回复 使用道具 举报
看作用域啊。。。。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马