Nearby lessons

46 of 125

Java - 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
Loading editor…
📝 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 Questions
Progress: 0 / 2

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.