public class Person{
static {
System.out.println("c");
}
}
//*****************************************************
//静态代码块
/**
* 特点:随着类的加载而执行,只执行一次,并优先于main函数执行
* 用于给类进行初始化
*/
public class StaticCodeDemo {
static {
System.out.println("a");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new Person();
new Person();
System.out.println("over");
}
static {
System.out.println("b");
}
}//*****************************
结果:a
b
c
over