Http://www.cnblogs.com/end/archive/2012/12/21/2827554.html
There are four blocks of code:
Normal code block: Inside the method, there is a block of code enclosed in curly braces.
For example:
public void Test () {System.out.println ("hij");
This is the code block {
int x; System.out.println ("Hello World," +x);} System.out.println ("Hello");
This is also the code block {return;}}
When you put the return code block to the front, that is, the return code block after the code, it will be an error.
When we have finished using X and no longer use X in the next code, there is no need for x to take up space in memory, which, in the case of a local code block, encapsulates the X and the area it is designed to be a partial block of code that is not changed in the execution of the program, but disappears after execution is complete.
Building blocks of code: blocks of code defined directly in the class, without the static keyword, which can initialize the object of the class
When a constructor in a class exists in an overloaded form, and there is a common member variable or a common method, it can be initialized by constructing a code block, which reduces the duplication of code!
Static code block: a code block decorated with static
Executes as the class loads, and executes only once.
takes precedence over the main function execution. Class can be initialized to
When the methods in the class are statically, and the constructor is private, it is not possible for us to instantiate this class, but to let the class add some properties, we can use the static code block
Java code block