输出如下:
Father Constructor
Son Constructor
Son
Father
Son outinfo()
Father outinfo()
各输出原因如下:
new Son()
调用 Son 无参构造方法,先调用了 super()
执行父类无参构造方法。new Son()
调用 Son 无参构造方法,执行父类无参构造方法后打印 Son Constructor
。test()
方法先打印 this.v
,this 表示当前实例 Son,因此打印 Son 中的 v 变量值为 Son
。test()
打印 super.v
,super 表示父类 Father,因此打印 Father 中的 v 变量值为 Father
。test()
执行 this.outinfo()
方法,this 表示当前实例 Son,因此执行 Son 的 outinfo 方法,打印 Son outinfo()
。test()
执行 super.outinfo()
方法,super 表示当前实例的父类 Father,因此执行 Father 的 outinfo 方法,打印 Father outinfo()
。