A Brief Look at Nested and Inner Classes

2014-11-24 10:43:47 · 作者: · 浏览: 0

In Java, you can create a class within another class and store them together such classes are nested classes. The containing class is the top-level class. There are four types of nested classes:

Static member classes: A static member class has access to all static methods of the top-level class.

Nonstatic member classes: also known as inner classes: This type of class requires an instance; it has access to all data and methods of the top-level class.

Local classes: These are local to a block of code.

Anonymous classes: These are local classes that have no identifier.