黑马程序员技术交流社区

标题: 给大家出个面试题 [打印本页]

作者: xiaobei56    时间: 2015-12-16 22:42
标题: 给大家出个面试题
  1. /*
  2. *面试题:
  3. *        要求:请填空分别输出30 , 20 ,10
  4. */
  5. class Outer{
  6.         public  int num =10;
  7.         class Inner{
  8.                 public int num=20;
  9.                 public void show(){
  10.                         int num=30;
  11.                         System.out.println(????);
  12.                         System.out.println(????);
  13.                         System.out.println(????)
  14.                        
  15.                 }
  16.         }
  17. }
  18. public class Test3 {
  19.         public static void main(String[] args) {
  20.                 Outer.Inner oi=new Outer().new Inner();
  21.                 oi.show();
  22.         }
  23. }
复制代码
.
.
.
.
.
.
..
.
.答案
System.out.println(num);
System.out.println(this.num);
//直接使用 Outer.num访问的话,Outer的成员变量num必须是静态的.
System.out.println(Outer.this.num);//还可以 (new Outer().num)




作者: xbin0316@qq.com    时间: 2015-12-18 07:59
学习了,很细致,果然不能来半点马虎。




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