In programming, how can we solve our problems when we encounter problems?
Start-up programming and compile a small program to easily see the desired results and answers!
Today I learned static {} static code blocks, but I don't know who should load them first with the static main () function?
So: I wrote a small piece of code:
The Code is as follows:
Package Stu. love. a; public class staticdemo1 {static {system. out. println ("A");}/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stubsystem. out. println ("B");} static {system. out. println ("C ");}}
Running result:
Conclusion: Load Static {} first!
Hands-on programming is a learning technique!
Why is static {} First loaded?
Because static {} is the initialization of the class! The variables in the class may be called in Main. Therefore, static Initialization is required first!