the Java static code block will run itself when the class is loaded?
The idea of a lot of Java developers was deeply raped by this thought N times, spreading the wrong thought of the blog, in a heap of online, more and more people were 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 must be loaded into the virtual machine};p ublic static void Main (string[] args) { System.out.println ("Hello word");}}
Run result: no "static Bolck" output
So when will the static block be called? I found an article that introduces a more specific blog.
Http://www.cnblogs.com/ivanfu/archive/2012/02/12/2347817.html
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
Java myth: Static code blocks, when the class will be loaded into its own initiative to run?