static block in Java
From: Javaeye Author: mht19840918 keywords: static
A structure such as static {} is often used in Java programs.
Such a structure is called a static block, typically a code that runs when a class is initialized. Note that the initialization of the class is not the initialization of the object.
That is, you define the object is the initialization code that it runs, and it runs only the first time it is defined. After that, the initialization is no longer running.
There can be a lot of static blocks in a class. Static blocks are executed sequentially.
Look at the following code: public class teststatic{
static{System.out.println (1); } static{System.out.println (2); public static void Main (string[] args) {System.out.println (5); } static{System.out.println (3); } static{System.out.println (4); The result is 1 2 3 4 5 at a glance, first calling static static fast code, and then invoking the Startup method. The execution order of the static blocks is the process of executing the code in the order in which it is written. Static blocks are used less, in fact, when the object is generated to produce a series of static variables.