简体   繁体   English

超类方法可以覆盖子类方法吗?

[英]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.我相信你应该通过 OOP 原则来更好地理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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