【发布时间】:2016-11-20 03:28:49
【问题描述】:
我在网上搜索了很长时间。但是没有用。请帮助或尝试给出一些想法如何实现这一点?为什么结果不是首先打印“int main”?我想知道为什么这个程序的结果如下?提前谢谢。
超级静态块
静态块 4
主要
超级构造函数
构造函数
class StaticSuper {
static {
System.out.println("super static block");
}
StaticSuper() {
System.out.println("super constructor");
}
}
public class StaticTests extends StaticSuper {
static int rand;
//static initialise
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();
}
}
【问题讨论】: