Java-Nested Classes

Nested Classes

You can put the definition of one class inside the definition of another class, that is called nested class. It is also known as inner class.

Program

1

Program Source

class Outer {
    
    class Inner {
    
        void innerMethod()
        {
            System.out.println("InnerMethod Called");
        }
    }
    
    void callInnerMethod()
    {
        Inner obj = new Inner();
        obj.innerMethod();
    }
    
    void outerMethod()
    {
        System.out.println("OuterMethod Called");
    }
}


public class Javaapp {
    
    public static void main(String[] args){
        
        Outer obj = new Outer();
        obj.callInnerMethod();
        obj.outerMethod();
   }
}

Leave a Comment