Java Inner Class (Nested class)
A class is declared within the class which is called inner class (or) nested class. The class which holds the inner class is called the outer class.
Syntax:
class OuterClass {
class InnerClass {
}
}
Example
public class Outerclass{
private int Age=30;
class Innerclass{
void showdata(){
System.out.println("Age is "+Age);
}
}
public static void main(String args[]){
Outerclass oc=new Outerclass();
Outerclass.Innerclass ic=oc.new Innerclass();
ic.showdata();
}
}
Types of Nested classes
There are divide into two types:
- Non-static nested class (Inner class)
- Member inner class
- Local inner class
- Anonymous inner class
- Static nested classes

Advantages of Inner classes
- Inner class can access all the data member of outside class.
- It is easily to develop read and maintain code.
- It is easy to optimize the code.
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com