JavaIntermediate#inner-classes

What is a local class in Java?

A class defined inside a method body, visible only within that method. It can access effectively final local variables of the enclosing scope, useful for encapsulating logic used only locally.

Example
void process() {
  class Helper { void help() { System.out.println("helping"); } }
  new Helper().help();
}

Related Questions

1
JavaBeginner#fundamentals

What is the difference between an enum and a class with constants?

Open
2
JavaIntermediate#fundamentals#java14

What are records in Java (Java 14+)?

Open
3
JavaAdvanced#fundamentals#java17

What is the difference between sealed classes and final classes (Java 17)?

Open