倒着看程序,即从主函数开始看:
1.new Zi()--------创建一个无参子类对象,调用Zi 类无参构造函数Zi(){}
2.在Zi 类中找到无参构造函数Zi(){ this(4); System.out.println("zi...run");}发现有this(4),this是本类引用,所以先调用对应的构造函数Zi(int X){}
3.找到对应的构造函数Zi(int X) Zi(int y){this(3,4); System.out.println("zi...run.......y");},发现有this(3,4)继续调用本类对应的构造函数Zi(int z,int a){}
4.找到对应构造函数 Zi(int z,int a){super(1111);System.out.println("zi...run.......z");},有super(1111),super为父类引用,即调用父类对应的构造函数Fu(int x){}
5.找到父类中对应的构造函数 Fu(int x){ super();System.out.println("fu...run");},虽然父类构造函数还有super(),但是其实这里引用的是Object(){},引用到这里就结束了,然后开始打印语句:刚刚倒着上来,现在顺着打印下去:fu...run zi...run.......z zi...run.......y zi...run
主要知识点就是构造函数中的this引用和super引用;
this为本类引用,super为父类引用
|