Accessing super class function using subclass object

前端 未结 5 1479
庸人自扰
庸人自扰 2021-01-18 22:08

I have an object of a subclass extending its superclass. There is an overridden method in subclass which can be called using the object. Is that possible to call the superc

5条回答
  •  醉酒成梦
    2021-01-18 22:53

    Is there any way to achieve this? No, there isn't.

    At runtime the JVM will pick the methods to call based on the instance type (that's polymorphism for you), not based on the type it is declared with.

    Your instance is a subclass instance, so the go() method in the subclass will be called.

提交回复
热议问题