Access outer class “super” from inner class in Java

Like this:

class Outer {
    class Inner {
        void myMethod() {
            // This will print "Blah", from the Outer class' toString() method
            System.out.println(Outer.this.toString());

            // This will call Object.toString() on the Outer class' instance
            // That's probably what you need
            System.out.println(Outer.super.toString());
        }
    }

    @Override
    public String toString() {
        return "Blah";
    }

    public static void main(String[] args) {
        new Outer().new Inner().myMethod();
    }
}

The above test, when executed, displays:

Blah
Outer@1e5e2c3

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)