* A: Code block overview
* In Java, code enclosed in {} is called a code block.
* B: code block classification
* Depending on their location and declaration, can be divided into local code block, construction code block, static code block, synchronous code block (multi-threaded interpretation).
* C: Application of common code blocks
* A: Local code block
* appear in method, limit variable life cycle, release early, improve memory utilization
public static void Main (string[] args) {
{
int i = 20;
System.out.println (i); A local code block is a block of code in a method that is valid only within {}
}
}
* B: Constructs a block of code (initialization block)
* occurs outside of a method in a class, the same code is stored together in multiple construction method methods, each call construct executes, and is executed before the method is constructed
Executes the code block once for each object created;
* C: Static code block
static {
}
* occurs outside the method in the class, with the static modifier, used to initialize the class, executes at load time, and executes only once.
* Initializes the class, typically for loading the driver
Static code block is better than Main method execution
java-code block (learn it yourself as a note)