Calling outer class function from inner class [duplicate]
I have implemented a nested class in Java, and I need to call the outer class method from the inner class.
class Outer {
void show() {
System.out.println("outter show");
}
class Inner{
void show() {
System.out.println("inner show");
}
}
}
How can I call the Outer
method show
?
You need to prefix the call by the outer class:
Outer.this.show();
This should do the trick:
Outer.Inner obj = new Outer().new Inner();
obj.show();