I remember that at the time of my graduation, I was most afraid of studying JAVA. I have never done anything wrong with this JAVA question. I finally reviewed this page today. After reading it for a long time, I had to remember what I learned.
1. execution sequence of static code segments
The execution result is as follows:
Cup (1)
Cup (2)
Cups ()
Cups ()
Inside main ()
F (99)
Ii. execution sequence of non-static code segments
The execution result is as follows:
Inside main ()
Mug (1)
Mug (2)
C1 & c2 initialized
Mugs ()
Mug (1)
Mug (2)
C1 & c2 initialized
Mugs ()
Conclusion: There is a lot of knowledge involved here, including code blocks, anonymous internal classes, and static initialization. I feel quite clear when using such a big example.
It should be mentioned that the initialization of static variables, methods, and code blocks is only once, that is, the initialization is run when the class is called for the first time. No matter how many times the class will be new, initialization will not be run.
Close! Next, let's look at the new concept ~