Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.9k points)

In the following snippet:

public class a {

    public void otherMethod(){}

    public void doStuff(String str, InnerClass b){}

    public void method(a){

        doStuff("asd",

            new InnerClass(){

                public void innerMethod(){

                    otherMethod();

                }

            }

        );

    }

}

Is there a keyword to refer to the outer class from the inner class? Basically what I want to do is outer.otherMethod(), or something of the like, but can't seem to find anything.

1 Answer

0 votes
by (46k points)

In prevailing, you try OuterClassName.this to refer to the enclosing instance of the outer class.

In your case that would be

a.this.otherMethod()

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 29, 2019 in Java by Suresh (3.4k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...