Java继承结构中类的初始化
Java继承结构中类的初始化的代码是怎样的你知道吗?你对Java继承结构中类的初始化了解吗?下面是小编为大家带来的'关于Java继承结构中类的初始化的知识,欢迎阅读。
Java继承结构中类的初始化
package nie.test.extend;
/** 子构造子的初始化过程:
* @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
System.out.print("d");
System.out.print(s);
}
{
b="r"; //6
System.out.print("a");
System.out.print(b);
}
Father() {
this("@");
System.out.print("1"); //8
}
Father(String s) {
System.out.print(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
System.out.print("t");
System.out.print(s);
}
{
b = "3"; //10
System.out.print("6");
System.out.print(b);
}
Son() {
System.out.print("."); //11
}
Son(String s) {
this();
System.out.print("com"); //12
}
}
【Java继承结构中类的初始化】相关文章: