标签:
(1)初始化对象的存储空间为零或null值;
(2)调用父类构造函数;
(3)按顺序分别调用类成员变量和实例成员变量的初始化表达式;
(4)调用本身构造函数。
例子:
public class Dollar extends Money{
Rmb r=new Rmb()
public Dollar(){
System.out.println("Dollar is construct!");
}
public static void main(String[] args){
new Dollar();
}
}
class Money{
public Money(){
System.out.println("Money is construct");
}
}
class Rmb{
public Rmb(){
System.out.println("RMB is construct");
}
}
输出结果:
Money is construct
RMB is construct
Dollar is construct!
我们再自己写一个程序,以测试运行顺序:
输出结果:
父类类成员变量说明此时的运行顺序为:
标签:
原文地址:http://www.cnblogs.com/wangsong/p/4903088.html