Java - (Inner|Nested) Class

Java Conceptuel Diagram


The Java programming language allows you to define a class within another class.

Nested or Inner ?

  • Nested classes that are declared static are called static nested classes.
  • Non-static nested classes are called inner classes and requires an instance of the outer class to be referenced.
class OuterClass {
    static class StaticNestedClass {
    class InnerClass {

When to use ?

  • If a class is useful to only one other class, then it is logical to embed it in that class and keep the two together.
  • It increases encapsulation but increase dependency
If you want to implement an hierarchy like of object see also Tree - Composite Type (Design Pattern)

Documentation / Reference

Discover More
Simple Class
Java - Class (Definition)

A java/lang/Classclass provides the blueprint for objects; you create an object from a class. All classes are derived from the Object class. A class declaration names the class and encloses the class...
Java Conceptuel Diagram
Java - Member of a class

The members of a class are the inherited components of the class body including: fields, methods, nested classes, interfaces, and enumerated types. Since constructors are not inherited,...

Share this page:
Follow us:
Task Runner