Casting to Superclass, and Calling Overriden Method

前端 未结 4 1802
梦如初夏
梦如初夏 2021-01-23 16:44

I have my next question. I have extended a class, Parrent and overridden one of its method in the Child class. I tried to cast the type to the supercla

4条回答
  •  星月不相逢
    2021-01-23 17:28

    The actual type is Child, therefore when you call a method, the Child's method will be called. It doesn't matter whether the reference type is of Parent, it's the actual type of the object that matters.

    You can't "cast to superclass" in order to call the Parent's method either.

提交回复
热议问题