Download the JDK
Search the Tutorials
Hide the TOC
Trail: Learning the Java Language
Lesson: Classes and Objects
Section: Nested Classes
Classes and Objects
Classes
Declaring Classes
Declaring Member Variables
Defining Methods
Providing Constructors for Your Classes
Passing Information to a Method or a Constructor
Objects
Creating Objects
Using Objects
More on Classes
Returning a Value from a Method
Using the this Keyword
Controlling Access to Members of a Class
Understanding Instance and Class Members
Initializing Fields
Summary of Creating and Using Classes and Objects
Questions and Exercises
Questions and Exercises
Nested Classes
Inner Class Example
Summary of Nested Classes
Questions and Exercises
Enum Types
Questions and Exercises
Annotations
Questions and Exercises
Home Page > Learning the Java Language > Classes and Objects
« Previous • Trail • Next »
Summary of Nested Classes

> A class defined within another class is called a nested class. Like other members of a class, a nested class can be declared static or not. A nonstatic nested class is called an inner class. An instance of an inner class can exist only within an instance of its enclosing class and has access to its enclosing class's members even if they are declared private.

> The following table shows the types of nested classes:

> > Types of Nested Classes
> > Type | Scope | Inner
> > --- | --- | ---
> > static nested class | member | no
> > inner [non-static] class | member | yes
> > local class | local | yes
> > anonymous class | only the point where it is defined | yes

« Previous • Trail • Next »
Previous page: Inner Class Example
Next page: Questions and Exercises: Nested Classes