java static code blocks are automatically executed when the class is loaded?
A lot of Java developers thought, by this thought deeply gang raped n times, spread the wrong thought of the blog, in the online heap, more and more people are gang-raped.
such as: http://blog.csdn.net/leeyu35/article/details/7755304
Then our procedure is to prove that this is a false statement:
Class MyClass1 {static {//Static blocks System.out.println ("static Block");}} public class Main {class[] Classarray = {myclass1.class//This class is referenced, it is necessary to load the class into the virtual machine};p ublic static void Main (string[] args) { System.out.println ("Hello word");}}
Execution result: "Static Bolck" is not output
So when will the static block be called? I found an article that introduces a more detailed blog.
Http://www.cnblogs.com/ivanfu/archive/2012/02/12/2347817.html
Java myth: Static blocks of code that are executed automatically when the class is loaded?