0Pricing
Java Academy · Lesson

Static Nested Classes

Define static nested classes as associated helper types without an enclosing instance reference.

Static Nested Classes

A static nested class is defined inside another class with the static keyword. It has no reference to the enclosing class instance — it is just logically grouped with it.

Declaring a Static Nested Class

Use the outer class name to access the nested class from outside.

class LinkedList<T> {
    private Node<T> head;

    // Static nested class — no outer instance reference
    private static class Node<T> {
        T data;
        Node<T> next;
        Node(T data) { this.data = data; }
    }

    public void addFirst(T item) {
        Node<T> node = new Node<>(item);
        node.next = head;
        head = node;
    }
}

All lessons in this course

  1. Static Nested Classes
  2. Inner Classes and Outer Access
  3. Local and Anonymous Classes
  4. Choosing the Right Nesting Strategy
← Back to Java Academy