| Author |
Order of Static initialization Block,Instance initialization Block and Constructor....
|
Shanu Pandey
Greenhorn
Joined: Mar 17, 2011
Posts: 18
|
|
If in a code we have a instance initialization code then that code is executed after the constructor's call to the super() is complete.
The output should be:
START
static - grandparent
static - parent
static - child
constructor - grandparent
instance - grandparent
constructor - parent
instance - parent
constructor - child
instance - child
END
But the actual Output is:
START
static - grandparent
static - parent
static - child
instance - grandparent
constructor - grandparent
instance - parent
constructor - parent
instance - child
constructor - child
END
please make it clear why??
|
 |
Matt Cartwright
Ranch Hand
Joined: Aug 25, 2008
Posts: 149
|
|
The instance initializer needs to
be executed before the constructor returns control.
This is how 'a' gets initialized
And the output is:
StaticTest - static
START
StaticTest - BEGIN - instance
a = 12
StaticTest - END - instance
StaticTest - constructor
a = 12
END
HTH
Matt
|
 |
 |
|
|
subject: Order of Static initialization Block,Instance initialization Block and Constructor....
|
|
|