/*****************************************************/ // INHERIT3 class A { public int x; } class B extends A { public int y = 3; public B(int y) { x = y; } } class C extends B { public int z; public C() { this(2); } private C(int x) { super(x+1); System.out.println("x (local): "+x); System.out.println("x (IV): "+this.x); System.out.println("y: "+y); System.out.println("z: "+z); } } public class inherit3 { public static void main(String[] args) { new C(); } } /* ----+--------------------------------------+---+---+--- Step| What Happens | x | y | z ----+--------------------------------------+---+---+--- 0 | Fields set to default values | 0 | 0 | 0 1 | C() constructor invoked | 0 | 0 | 0 2 | C(x) constructor invoked with $this$ | 0 | 0 | 0 3 | B(y) constructor invoked with $super$| 0 | 0 | 0 4 | A() constructor invoked with $super$ | 0 | 0 | 0 5 | Object constructor invoked | 0 | 0 | 0 6 | x field initialized | 0 | 0 | 0 7 | A() constructor executed | 0 | 0 | 0 8 | y field initialized | 0 | 3 | 0 9 | B(y) constructor executed | 3 | 3 | 0 10 | z field initialized | 3 | 3 | 0 11 | C(x) constructor executed | 3 | 3 | 0 12 | C() constructor executed | 3 | 3 | 0 ----+--------------------------------------+---+---+--- */