Java繼承結構中類的初始化的代碼是怎樣的你知道嗎?你對Java繼承結構中類的初始化了解嗎?下面是小編爲大家帶來的'關於Java繼承結構中類的初始化的知識,歡迎閱讀。
Java繼承結構中類的初始化package nd;
/** 子構造子的初始化過程:
* @author dotjar
* 1.父static域
* 2.父static塊
* 3.子static域
* 4.子static塊
* 5.父普通域
* 6.父普通塊{}
* 7.父構造子
* 8.子普通域
* 9.子普通塊{}
* 10.子構造子
*/
public class Test {
public static void main(String[] args) {
new Son("s");
}
}
class Father {
static protected String s = "father_static_property_string"; //1
protected String b = "father_normal_property_string"; //5
static {
s = "o"; //2
t("d");
t(s);
}
{
b="r"; //6
t("a");
t(b);
}
Father() {
this("@");
t("1"); //8
}
Father(String s) {
t(s); //7
}
}
class Son extends Father {
public static String s = "son_static_property_string"; //3
public String b = "son_normal_property_string"; //9
static {
s = "j"; //4
t("t");
t(s);
}
{
b = "3"; //10
t("6");
t(b);
}
Son() {
t("."); //11
}
Son(String s) {
this();
t("com"); //12
}
}