static{}>{}>构造器
static{} 只是在第一次执行
优先执行父类
运行结果 : 父类static{} 子类static{} 父类{} 父类构造器 子类{} 子类构造器
base static + test static+base...+base constructor+test...+ test constructor
package org.zvc;
public class TestStatic extends Base{
{
System.out.println("test ...");
}
static{
System.out.println("test static");
}
public TestStatic(){
System.out.println("test constructor");
}
public static void main(String[] args) {
new TestStatic();
new TestStatic();
// base static + test static + base... + base constructor + test ...+test constructor
// base... +base constructor + test...+ test constructor
}
}
class Base{
{
System.out.println("base ...");
}
static{
System.out.println("base static");
}
public Base(){
System.out.println("base constructor");
}
}