jvm虛擬機

  1. 類的加載連接和初始化

            驗證問題:①對於靜態字段來講,只有直接定義了該字段的類纔會被初始化;class

                             ②當一個類在初始化時,要求其父類都已經初始化完畢了static

            驗證代碼:co

            

public class MyTest1 {
    public static void main(String[] args) {
        System.out.println(MyChild1.str2);
    }
}

class MyParent1{
    public static String str= "hello world";

    static {
        System.out.println("Myparent1 static block");
    }
}

class MyChild1 extends MyParent1{

    public static String str2 = "welcome";
    static {
        System.out.println("MyChild1 static block");
    }
}
相關文章
相關標籤/搜索