一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Overloading overriding runtime type and object ori

时间:2008-01-12 编辑:简简单单 来源:一聚教程网

Objective 3)
Write code to construct instances of any concrete class including normal top level classes inner classes static inner classes and anonymous inner classes.
Inner Classes
・    A class can be declared in any scope. Classes defined inside of other classes are known as nested classes. There are four categories of nested classes.
Top-level nested classes / interfaces
・    Declared as a class member with static modifier.
・    Just like other static features of a class. Can be accessed / instantiated without an instance of the outer class. Can access only static members of outer class. Can’t access non-static instance variables or methods.
・    Very much like any-other package level class / interface. Provide an extension to packaging by the modified naming scheme at the top level.
・    Classes can declare both static and non-static members.
・    Any accessibility modifier can be specified.
・    Nested interfaces are implicitly static (static modifier also can be specified). They can have any accessibility modifier. There are no non-static inner, local or anonymous interfaces.
Non-static inner classes
・    Declared as a class member without static.
・    An instance of a non-static inner class can exist only with an instance of its enclosing class. So it always has to be created within a context of an outer instance.
                Outer.Inner i = new Outer().new Inner();
・    Just like other non-static features of a class. Can access all the features (even private) of the enclosing outer class. Have an implicit reference to the enclosing instance.
・    Cannot have any static members.

热门栏目