试图绕过这段代码。当我运行它时 - 输出将是Roger。msg 不是一个静态变量,因此应该在类级别打印Moore吗?
编辑:我也允许睡眠允许子线程运行它的过程。它还打印打印... 仍然没有变化
public class Test2 {
private static String msg = "Roger";
static {
new Thread(new Runnable() {
public void run() {
System.out.println("printing..");
msg += "Moore";
}
}).start();
}
static {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
public static void main(String argv[]) {
System.out.println(msg);
}
}