Inner Classes
Home ] Up ] Introduction ] Java Resources ] The Java Environment ] Java Language Fundamentals ] Objects and Arrays ] Operators ] Statements ] Classes and Objects ] Packages ] Inheritance & Polymorphism ] The Java Class Library ] [ Inner Classes ] Graphics Programming ] Events ] Swing GUI Components ] Applets ] Exceptions ] Generic Programming ]

 

Nested Classes in C++
A Stack Class
Inner Class Types
Benefits of Inner Classes

 

What are Inner Classes?

An inner class is one that is defined within another class.

Why is this good thing?  Here are some reasons:

  • An inner class can make clear an explicit relationship with the enclosing class.
  • An inner class can be hidden within the enclosing class. (Data hiding/encapsulation.)
  • Certain kinds of inner classes can access all the fields and methods within the enclosing class, which can be very helpful.

The bottom line is that using inner classes can lead to more readable, more maintainable, and more reliable code.

 

This page was last modified on 27 November, 2007