Skip to content

Instantly share code, notes, and snippets.

@nyux
Created July 27, 2014 16:18
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 nyux/3aedbefcb22c8bf86fd6 to your computer and use it in GitHub Desktop.
Save nyux/3aedbefcb22c8bf86fd6 to your computer and use it in GitHub Desktop.
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