Nearby lessons
46 of 125Java - Static Nested Class
📌 What You Will Learn
- What an inner class is and why we need it
- The four types: member, static nested, local, anonymous
- How to create objects of inner classes
- Where anonymous inner classes are used in real projects
Static Nested Class is a core concept of the Java language. This lesson explains Static Nested Class with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
Static Nested Class
If we put the keyword static before the inner class, it becomes a static nested class. It does not need an outer object — you can create it directly with the outer class name.
In simple words: A static nested class belongs to the outer class, not to an outer object. Create it directly with Outer.Nested n = new Outer.Nested(); — no outer object is needed.
Example01
📝 Key Takeaways
- Inner class = a class declared inside another class.
- Member inner class needs an outer object: outer.new Inner().
- Static nested class is created with Outer.Nested, no outer object needed.
- Local inner class lives inside a method.
- Anonymous inner class has no name and is used for one-time implementations.
- Modern code prefers lambda expressions for one-method interfaces, but anonymous classes still appear in real projects.
🧠 Test Your Knowledge
2 QuestionsProgress: 0 / 2