What is a nested class?

Solution:

The nested class can be defined as the class which is defined inside another class or interface. We use the nested class to logically group classes and interfaces in one place so that it can be more readable and maintainable. A nested class can access all the data members of the outer class including private data members and methods. The syntax of the nested class is defined below.

class Java_Outer_class{  
 //code  
 class Java_Nested_class{  
  //code  
 }  
}  

There are two types of nested classes, static nested class, and non-static nested class. The non-static nested class can also be called as inner-class

0 answers