static code block

static {

  //...

}

1. Static code blocks cannot exist within methods and will only be executed once

2. When the static code block is located in the class where the main method is located, the static code block is executed before the main method of the program runs.

3. When the static code block is located in a class other than the main method, when the main method calls a static member of the class or creates an object of the class, the static code block will be executed, and it will take precedence over the current call statement or the construction of the class method

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325086798&siteId=291194637