Casting to Superclass, and Calling Overriden Method

前端 未结 4 1852
梦如初夏
梦如初夏 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:19

    Here the child method gets called because functions are bind at runtime and in your reference memory is of child

    ((Parrent) new Child()).test();// new Child() means memory is of child

提交回复
热议问题