<span style="font-size:18px;">
/**
* static 修饰的代码块是属于类的,随着类的加载而加载
* @author Mr.Gao
*/
public class TestStatic extends Base {
static {
System.out.println("1");
}
public TestStatic() {
System.out.println("2");
}
public static void main(String[] args) {
new TestStatic();
}
}
class Base {
static {
System.out.println("3");
}
public Base() {
System.out.println("4");
}
}</span>
运行的结果是什么呢?
留个悬念。。。
。
。。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
结果是
3
1
4
2