1
當我運行這個代碼時,它輸出blockA blockB blockA
。我期望輸出爲blockB blockA blockA
。意外的Java文本輸出
爲什麼輸出blockA blockB blockA
而不是blockB blockA blockA
?
public class Test
{
public static Test t1 = new Test();
{
System.out.println("blockA");
}
static
{
System.out.println("blockB");
}
public static void main(String[] args)
{
Test t2 = new Test();
}
}
變量靜態塊之前被初始化。 https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html –