The code block here refers to the code block enclosed by {}, which is independent of the method body, including static code blocks and non-static code blocks. For example:
Class {
Static int x = 0; // static attribute
Int y = 1; // non-static attribute
Static {
// Static code block
}
{
// Non-static code block
}
Public (){
// Constructor
}
Public static void main (string [] ARGs ){
A class1; // load the class
A = new A (); // instantiate and create an object
}
}
The execution sequence can be summarized as follows:
1. Static attributes and static statement blocks are all completed during class loading, and non-static objects are executed during object creation.
2. the initialization sequence of a single class is as follows:
Allocate and assign values to static attributes-> execute static code blocks-> allocate memory for non-static attributes and assign values-> execute non-static code blocks-> constructor.
3. the initialization sequence of the inherited classes is as follows:
Parent static-> parent static block-> child static block-> parent non static block-> parent structure-> child non static-> sub-non-static blocks-> sub-structures.
View articles for details
Http://topic.csdn.net/u/20100302/17/b796145c-2495-4c42-8ea1-af5c76e85e4b.html