Member class declarations  describe nested classes that are members of the surrounding class. Member classes may be static, in which case they have no access to the instance variables of the surrounding class; or they may be inner classes .(出自Java Language Specification)
测试程序:class WithInner{
     int out=9;
   static  class Inner{
       WithInner w=new WithInner();
     Inner(){
          
        System.out.println("Inner()");
      }
    
    void f(){
         System.out.println (w.out);
        System.out.println ("in Inner...");
     }
   }
}public class Main{
   public static void main(String[] args){
     
    WithInner.Inner i = new WithInner.Inner();
      i.f();
        }
}
按照书上的说法,嵌套内部类不能使用外部类的对象,但这个程序可以通过,为什么????

解决方案 »

  1.   

    in which case they have no access to the instance variables of the surrounding class;
    这句话好象是说嵌套类不能够直接访问外部类的成员变量,比如如果直接访问OUT变量就不能通过,如果是实例化了一个外部类类型的对象,如 WithInner w=new WithInner(),再访问W.OUT就没有问题了.
    这只是我的理解,看高手怎么解答.
      

  2.   

    TIJ 3rd 第8.2.5
    “不能从嵌套类的对象中访问非静态的外围类对象”
    这句话是什么意思啊,请指点!!!
      

  3.   

    http://community.csdn.net/Expert/topic/4337/4337439.xml?temp=9.267825E-02
      

  4.   

    Member class declarations  describe nested classes that are members of the surrounding class. Member classes may be static, in which case they have no access to the instance variables of the surrounding class; or they may be inner classes .(出自Java Language Specification)
    《Java Language Specification Third Edition》这本书可能都知道吧
    难道是他出错了?????