1. Publicstatic void Main () method, static and public can be swapped position, can be final decorated, can also be synchronize decorated.
2. A static block of code in a class executes before the main method, regardless of whether the static code block precedes or follows main. Precisely, this is because a static block of code executes when the class is loaded and executes only once. The main method is the class-loaded portal, which loads the class (new) when it encounters main, and then loads the static code block (either before or after main) before executing the contents of the main method. A non-static block of code is executed every time the new object. The static code block is loaded only once , and if main is already executed, then new is no longer executed.
3. Initialization order: The parent class takes precedence over the subclass, initializes the parent class and initializes the subclass, but note that the static code block is special, because the static code block is in the class load phase and takes precedence over other parts, so the parent class and subclass static code blocks are loaded, and the other parts of the parent class and subclass are loaded first.
(1) Parent class static code blocks (including static initialization blocks, static properties, but not static methods)
(2) subclass static code blocks (including static initialization blocks, static properties, but not static methods)
(3)parent class non-static blocks of code (including non-static initialization blocks, non-static properties)
(4) Parent class constructor
(5) Subclass non-static block of code (including non-static initialization blocks, non-static properties)
(6) Sub-class constructors
4. Scope
5.
Java Interview Knowledge points