能详细解释为什么是这个输出嘛

img

img

输出如下:

Father Constructor
Son Constructor
Son
Father
Son outinfo()
Father outinfo()

各输出原因如下:

  • Father Constructornew Son() 调用 Son 无参构造方法,先调用了 super() 执行父类无参构造方法。
  • Son Constructornew Son() 调用 Son 无参构造方法,执行父类无参构造方法后打印 Son Constructor
  • Sontest() 方法先打印 this.v,this 表示当前实例 Son,因此打印 Son 中的 v 变量值为 Son
  • Fathertest() 打印 super.v,super 表示父类 Father,因此打印 Father 中的 v 变量值为 Father
  • Son outinfo()test() 执行 this.outinfo() 方法,this 表示当前实例 Son,因此执行 Son 的 outinfo 方法,打印 Son outinfo()
  • Father outinfo()test() 执行 super.outinfo() 方法,super 表示当前实例的父类 Father,因此执行 Father 的 outinfo 方法,打印 Father outinfo()