Java: Calling super method of outer class from inner class

You use the syntax OuterClass.super.method(). Here's an example:

class Base {
    void method() {
        System.out.println("Base");
    }
}

class OuterClass extends Base {
    class Inner {
        void test() {
            OuterClass.this.method();  // "Outer"
            OuterClass.super.method(); // "Base"
        }
    }

    @Override
    public void method() {
        System.out.println("Outer");
    }
}

See also: Calling method of outer class from inner class

Comments

Be the first to comment!