This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
This is the flow - super class constructor executes and then the instance variables are initialized with the assigned values.
1. So when you create a object of C, B's constructor is called by the compiler inserted super(). So your C class constructor will actually be like below after compilation.
2. Now the B constructor runs and prints "form construcor1 NB". There is a call to print2() method.
3. Though at compile time it looks like a call to print2() of B, during runtime since the actual object created is for C, due to method overriding the print2() in C gets called.
4. Since instance variables are not given values till super class constructor is finished, the instance variable NStatic is still null when print2() is called from B's constructor and hence "from Method2 null" is printed.
5. Super class constructor ends and now instance variables are assigned respective values and hence NC is printed for NStatic field henceforth.