Http://www.cnblogs.com/teamleader/archive/2011/01/25/1944810.html
Object Instantiation sequence that you may not knowGuess the input of the following code. I expect more than 90% of people will not give the correct answer.Void Main ()
{
InitSeqBase x = new InitSeqChild ();
}
Public class InitSeqBase
{
Public static Nothing _ SField = new Nothing ("base static field initializer ");
Static InitSeqBase ()
{
Console. WriteLine ("base static constructor ");
}
Public Nothing InsField = new Nothing ("base Instance field initializer ");
Public InitSeqBase ()
{
Console. WriteLine ("base Instance constructor ");
}
}
Public class InitSeqChild: InitSeqBase
{
Public static Nothing _ SField = new Nothing ("child static field initializer ");
Static InitSeqChild ()
{
Console. WriteLine ("child static constructor ");
}
Public Nothing InsField = new Nothing ("child Instance field initializer ");
Public InitSeqChild ()
{
Console. WriteLine ("child Instance constructor ");
}
}
Public class Nothing
{
Public Nothing (string s)
{
Console. WriteLine (s );
}
} The answer is here (visible after selection, in a white font ):
child static field initializer
child static constructor
child Instance field initializer
base static field initializer
base static constructor
base Instance field initializer
base Instance constructor
child Instance constructor
Thank you for your participation!
Published by Wiz