Created
July 27, 2014 16:18
-
-
Save nyux/3aedbefcb22c8bf86fd6 to your computer and use it in GitHub Desktop.
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
public class Parent { | |
public int x = 0; | |
public Parent(int x) { this.x = x; } | |
public class InnerChild extends Parent { | |
public int x = 1; | |
public InnerChild(int x) { | |
super(2 * x); | |
this.x = x; | |
} | |
public void innerMethod(int x) | |
{ | |
outerMethod(x); | |
System.out.println(x); | |
System.out.println(this.x); | |
System.out.println(super.x); | |
System.out.println(Parent.this.x); | |
} | |
} | |
public void outerMethod(int x) | |
{ | |
System.out.println(x); | |
System.out.println(this.x); | |
} | |
public static void main(String [] args) | |
{ | |
int x = 37; | |
Parent p = new Parent(x); | |
x = 6; | |
Parent c1 = p.new InnerChild(x + 1); | |
InnerChild c2 = p.new InnerChild(x - 1); | |
p.outerMethod(2); | |
c1.outerMethod(3); | |
c2.innerMethod(4); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment