Created
May 28, 2013 16:34
-
-
Save fcamel/5664081 to your computer and use it in GitHub Desktop.
Java's special syntax to access 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
$ cat Outer.java | |
class Outer { | |
class Inner { | |
void foo() { | |
System.out.println(Outer.this.x); | |
} | |
} | |
private int x = 3; | |
public static void main(String[] args) { | |
Outer outer = new Outer(); | |
Inner inner = outer.new Inner(); | |
inner.foo(); | |
} | |
} | |
$ javac Outer.java | |
$ java Outer | |
3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment