What are inner classes?
- A class that is nested within a class is called as inner classes.
- The inner class can access private members of the outer class.
- It is mainly used to implement data structure.
- It is a part of nested classes.
- Non-static nested classes are known as Inner classes.
Syntax:class Outer_Java_Class
{
//Statements
class Inner_Java_Class
{
//Statements
}
}
Advantages of Inner Class:- It can access all the data members and methods of outer class, including private data members and methods.
- This class is used to make code more readable and maintainable.
- Inner class requires less code to write.