Java-Access Inner Class

Access Inner Class

An object of Inner class cannot be created without an object of outer class. Create the inner object within the outer object with this following syntax :

Program

1

Program Source

class Outer {

    void outerMethod() {
        System.out.println("OuterMethod Called");
    }

    class Inner {

        void innerMethod() {
            System.out.println("InnerMethod Called");
        }
    }
}

public class Javaapp {

    public static void main(String[] args) {

        Outer outer = new Outer();
        outer.outerMethod();
        Outer.Inner inner = outer.new Inner();
        inner.innerMethod();
    }
}

Leave a Comment