hi
here is the concept of overriding...... the method add()implemented by Class A is overridden by the Class B....... so both classes A & B when they are called use the same method add()declared in Class B i.e. the concept is always the parent class refers to the overidden method in the child class but the reverse is not true.......
Steps Of Execution...
1)When B b = new B(); is called the cursor moves to Class A where the default value of variable i changes from zero to 1 in the static block bcz static block is the first to executed when a class is loaded.
2)Now the cursor jumps to the Class B as it extends Class A the cursor again moves back to Class A constructor where the method add() is called. Now the cursor moves to Class B overriden method add()here the super.add()take the cursor back to Class A method add() where the value of i changes from 1 to 1+10 = 11 then cursor is again back to Class B overriden method add()where the value of i is changed from 11 to 11+20 = 31
3)Now the Constructor Class B is called so again the cursor moves back to Class B overriden method add() the cursor moves to Class A method add() where the value of i changes from 31 to 31+10 = 41 then cursor is again back to Class B overriden method add()where the value of i is changed from 41 to 41+20 = 61
4) Now the once the Class B has been instantiated the value of i is 61 thus the print statement would print the value as 61.
........ I hope this is clear ........