Nested Class Rules
Nested classes have many confusing rules. Table 6-1 will help you keep them straight.
Table 6-1. Nested class references
Type
|
Scope
|
Access
|
Keywords
|
|
method
|
instance
|
class
|
method final
|
class final
|
class static
|
instance
|
abstract/final
|
private
|
protected
|
public
|
Anonymous
|
|
|
|
|
|
|
|
|
|
|
|
Limited-scope
|
|
|
|
|
|
|
|
|
|
|
|
Inner
|
|
|
|
|
|
|
|
|
|
|
|
Static nested
|
|
|
|
|
|
|
|
|
|
|
|
Although most of the nested classes in this chapter are not recommended for routine use, it is important that you understand their dynamics. You may come across these nested class types down the line, and knowing how they work could save you time and frustration. Although many developers tend to overuse nested classes, they can be a valuable asset to your development process. When it comes to modeling composition relationships and implementing internals of a class that you want to hide, they can't be beat. |