nested class
A class declared inside another class, which the compiler still writes to its own class file.
In more detail
A static nested class, like Heavy inside Lazy in the course, is an ordinary class that happens to be grouped with its outer class. It is loaded and initialized on its own schedule. Its class file is named Outer$Inner.class.
Example
Lazy.java compiles to Lazy.class and Lazy$Heavy.classRelated terms
- class — A blueprint in code that bundles data and the functions that work on it, from which objects are made.
- class file — The file javac writes for each class, holding that class's bytecode plus a description of its fields and methods.
- static initializer — A block marked static inside a class that runs exactly once, the first time the class is actually used.
Taught in
- The Lifecycle Of A Java Program — Modern Java: Virtual Threads & High-Throughput Services
- Sealed Types And Exhaustiveness — Modern Java: Virtual Threads & High-Throughput Services
- Sprint: Values And Flow — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Objects, Nested Classes And Garbage Collection — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep