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 optimized for basic learning, practice and more. Examples are well checked and working examples available on this website but we can't give assurity for 100% correctness of all the content. This site under copyright content belongs to Onlinetpoint. You agree to have read and accepted our terms of use, cookie and privacy policy.