Skip to content

Instantly share code, notes, and snippets.

@mmhan
Created October 20, 2011 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmhan/1301181 to your computer and use it in GitHub Desktop.
Save mmhan/1301181 to your computer and use it in GitHub Desktop.
Inner class accessing outer class
/***
* 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