Hello All,
I have some confusion about class loading and initialization sequence.Here is what I understood.
1 ) Static statements/static blocks are executed.
2) Instance variables are assigned default values
3) Instance variables are initialized
4) constructor runs
5) Instance initialization block(s) run after all the call(s) to super has(have) been completed but before the rest of the constructor is executed.
6) Rest of the constructor is executed.
This is my sample program.
and this is the output
sM1 called with Parameter a
a
Static Initialization Block
sM1 called with Parameter b
b
sM1 called with Parameter c
c
sM1 called with Parameter 2
2
Initialization Block running
sM1 called with Parameter 3
3
sM1 called with Parameter 4
4
After Instance Initialization Block
constructor called
sM1 called with Parameter 1
1
I was hoping to see 4 printed after 2 but its printing 3
???
Could anyone kindly explain why
.
Waiting for a favorable reply. Thanks in advance.
Kind Regards.
Hasnain Javed Khan