Access the enclosing class from an inner classTag(s): Language
public class TestIt { public static void main(String a[]){ new TestIt().doit(); /* output : Hello world! */ } public void doit() { new InnerClass().sayHello(); } public void enclosingClassMethod(){ System.out.println("Hello world!"); } class InnerClass { public void sayHello() { TestIt.this.enclosingClassMethod(); } } }
public class TestIt { TestIt testItClass = this; public static void main(String a[]){ new TestIt().doit(); /* output : Hello world! */ } public void doit() { new InnerClass().sayHello(); } public void enclosingClassMethod(){ System.out.println("Hello world!"); } class InnerClass { public void sayHello() { testItClass.enclosingClassMethod(); } } }
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com