简体   繁体   中英

Can a super class method override a sub class method?

我知道子类可以覆盖超类方法,但它可以反过来工作吗?

In short: No

There's no reason why this should exist. If you have a superclass method that you want to use, then you simply don't implement an override for it in your subclass. If you don't want to use the superclass' implementation, then you write your override in a subclass.

不,它不能反过来工作。

No

A subclass is aware of existence of the superclass but a superclass is not aware of all its subclasses. Assuming, overriding is possible it would lead to lot of issues. How would you resolve which method needs to be called subclass or superclass?
I believe you should go through the OOP principles to understand better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM