28 What is nested class, static class and inner class?

What is nested class, static class and inner class?

Java allows declare a class inside another class.
Class inside another class is called nested class and class contain another class is called outer class.
Nested class declare with static keyword will be static nested class other it will be inner class.

Comparae static class and inner class?

There different point between static class and inner class:

  •  Static class can initialize without instance of outer class but inner class only exist if it was wrapper by a outer class
  • Inner class can access both static and non static member from the outer class but static class only can access the static member from outer class

When we should use static class?

  • Nested class help program more readable, reusable and easy to maintain
  • We can model a part of a system or outer class into a nested class or we can create some data structure inside outer class

Leave a Reply

Your email address will not be published. Required fields are marked *