当一个内部类被声明为static时,那么它无法访问到外部类的成员即:不能应用外部类成员,就算在其中创建一个外部类句柄(为什么把内部类声明为static让人很迷惑,声明之后会产生什么效果呢?)
  而在thinking in java 中有一段语句让人很摸不着头脑:
class tested 
{
  tested(){}
  void f();
  public static class testinner
 {
   public static void main(string[] args)
   {
    tested t=new tested();
    t.f();
   }
  }
}
//不是说不能应用外部类成员吗?很郁闷!!!!!!
 

解决方案 »

  1.   

    class tested 
    {
      tested(){}
      void f(); 
      public static class testinner
     {
       public static void main(string[] args)
       {
        tested t=new tested();
        t.f();
       }
      }
    }void f(); 这是方法?方法体呢??
      

  2.   

    建议楼主看看这篇文章:http://www.graphics.net.cn/article/java/java_static.asp
      

  3.   

    non-static内部类不能有static的成员,static内部类可以non-static内部类一般是些承载数据的结构或者说联合数据类型。
    通常情况下是一些小对象。而static内部类一般是相对独立的小模块。
    用于测试很不错。:)因为:
    内部类没有独立的源代码文件
    编译之后却又是独立的class文件。
    调试的时候可以调用内部类的方法对外部类做全面的诊断(包括private的成员和方法),
    发布的时候只要删除那些class文件就可以了。