Here the rule is that before doing anything in the constructor, the constructor of super class will be called. The other rule is that after all the constructor call over, the instance variable initialization happens.
Here I am giving you the sequence.
1.First new B(), this calls the B class constructor, this calls the super(2) first.
2.This super(2) assign the variable val as 2. This is A class val variable.
3.Now the instance variable of B class assignment happens, this assign the val variable of B class with 1
4.At this point, the B class has two val variable access, one with class A value(2) and other with class B value(1).
5.After this on the B class object we are calling the nested class C class object.
6.In the constructor of C class we are calling first super(4), as the super class is A, the val variable for A is again assigned to value 4.The B class val is still 1 and B class�s A class val value is still 2 and still accessible.
7.Finally we assign the val variable in C class as 3
8.So first we are printing the B class variable 1
9.Then C class local variable 3
10.Then we have used the super which is A class variable for C, that is 4.
11.Add one other statement
a.System.out.println(B.super.val);
It will give that hidden 2 value for B class�s A class val variable.