可做如下简单测试:
calss A { static int a; public A{ System.out.println("constructor of A"); } static { System.out.println("static block"); } public static void main(String[] args){ A aclass = new A(); A bclass = new A(); } }测试结果:
static block constructor of A constructor of A
测试结论:static代码块是在构造函数之前执行的,而且只执行一次,即类首次加载时。