class StaticSuper{
static{
System.out.println("super static block");
}
StaticSuper(){
System.out.println("super constructor");
}
}
public class StaticTests extends StaticSuper{
static int rand;
static{
rand=(int)(Math.random()*6);
System.out.println("static block "+rand);
}
StaticTests(){
System.out.println("constructor");
}
public static void main(String[] args){
System.out.println("in main");
StaticTests st=new StaticTests();
}
}
为什么运行结果第一行输出的是
super static block
而不是
static block |