Created
October 20, 2011 13:44
-
-
Save mmhan/1301181 to your computer and use it in GitHub Desktop.
Inner class accessing outer class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* http://www.java-forums.org/java-tips/6296-inner-class-accessing-outer-class.html | |
**/ | |
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment