class Person{ public String name = "liuqing"; Person(){ System.out.println("person construct"); }}class StaticTest { /** 构造方法*/ public StaticTest() { System.out.println("构造函数被执行了!"); } static Person person = new Person(); /** 静态代码快*/ static { System.out.println("静态代码块被执行了!"); //show(); } /** 静态方法*/ public static void show(){ System.out.println("静态方法被执行了!"); } } public class teststatic { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub StaticTest st = new StaticTest(); }}
结果:
person construct
静态代码块被执行了!
构造函数被执行了!