In Java super.getClass() prints “Child” not “Parent” - why is that?

后端 未结 3 903
[愿得一人]
[愿得一人] 2020-12-07 02:07

In Java classes and objects, we use \"this\" keyword to reference to the current object within the class. In some sense, I believe \"this\" actually returns the object of it

3条回答
  •  抹茶落季
    2020-12-07 02:29

    The super keyword will call an overridden method in the parent. Child did not override that method. So it will faithfully return the correct class which is Child. You do not get an instance of the Parent class this way.

提交回复
热议问题