C H A P T E R 3
Exploring Advanced Language Features
supportforclassesandobjects. Chapter3 buildsontothisfoundationbyintroducingyou
toJava'sadvanced language features, specifically thosefeatures related tonestedtypes,
packages, static imports, exceptions, assertions, annotations, generics, and enums.
Classes that are declared outside of any class are known as top-level classes . Java also
supports nested classes,whichareclassesdeclaredasmembersofotherclassesorscopes.
Nested classes help you implement top-level class architecture.
There are four kinds of nested classes: static member classes, nonstatic member
classes, anonymous classes, and local classes. The latter three categories are known as
inner classes .
Static Member Classes
A static member class isa static memberofanenclosingclass.Althoughenclosed,it
instance fields and invoke its instance methods. However, it can access the enclosing
class's static fieldsandinvokeits static methods,eventhosemembersthatarede-
clared private . Listing 3-1 presents a static member class declaration.
Listing 3-1. Declaring a static member class