Nested Class,Inner Class,Member Class,Local Class, and Anonymous class区别

Nested Class,Inner Class,Member Class,Local Class, and Anonymous class区别

其实所有类都可能是top level类或是nested 类;
所有的nested 类都可能是static类或是Inner类;
所有的Inner类都可能是local类,Anonymous类,non-static 的Member类;
top level 类不能是nested类.
Nested Class是C++的说法,通常JAVA说的是Inner Class.
可以是这样的层次:nested ->Inner->Anonymous
class TopLevelClass
{
  //这是Inner类,也是nested 类
  class NestedNonStaticClass{
  }
  //这是个static 类,也是nested 类
  static class NestedStaticClass{
  }

  void someMethod(){
    //这是个local类,不能是static类
    class LocalClass{
    }
    //方法中引用
    SuperOfAnonymousClass soac = new SuperOfAnonymousClass(){
    }
  }
}
//这是个Anonymous类
class SuperOfAnonymousClass{
}
 

你可能感兴趣的:(java)