Static nested class vs. a non-static one - Java

Static nested class vs. a non-static one

A static nested class can not directly access non-static methods or fields of an instance of its enclosing class. They can be accessed by creating the object of the nested inner class. Where as non-static nested class can access to the methods or fields of its enclosing class without creating their instance.

The object creation of a static nested class must be qualified with its inner class. Where as non-static inner class object will be created with its name alone.

Static inner class instance occupies less memory space. Where as the object of non-static inner class occupies more space than static inner class.
When we should make an instance variable private - Java
An instance variable can be declared as private to promote information hiding. So that no other object can access them...
Overridden methods in Java
Overridden methods of super class in subclass allow a class to inherit and behave close enough...
Is C++ access specifier called protected is similar to Java’s?
The java access specifier ‘protected’ is placed proceeding the member of the class and the access control is applicable only for that particular definition...
Post your comment