|
Nested top-level classes, Member classes, Localclasses, Anonymous classes Nested top-level classes- If youdeclare a class within a class and specify the static modifier, the compilertreats the class just like any other top-level class. Any class outside the declaringclass accesses the nested class with the declaring class name acting similarlyto a package. eg, outer.inner. Top-level inner classes implicitly have accessonly to static variables.There can also be inner interfaces. All of these areof the nested top-level variety. Member classes - Member innerclasses are just like other member methods and member variables and access tothe member class is restricted, just like methods and variables. This means apublic member class acts similarly to a nested top-level class. The primarydifference between member classes and nested top-level classes is that memberclasses have access to the specific instance of the enclosing class. Local classes - Local classes arelike local variables, specific to a block of code. Their visibility is onlywithin the block of their declaration. In order for the class to be usefulbeyond the declaration block, it would need to implement a more publiclyavailable interface.Because local classes are not members, the modifierspublic, protected, private, and static are not usable. |
|
共 1 个关于本帖的回复 最后回复于 2013-8-16 15:18