简体   繁体   English

为什么说接口完全抽象时接口支持多重继承?

[英]Why is it said interface support multiple inheritance when the interface is completely abstract?

I mean we are actually not inheriting anything from the interface. 我的意思是我们实际上没有从接口继承任何东西。 It is in the concrete class that we define what the methods are suppose to do. 在具体的类中,我们定义了应该执行的方法。

Interfaces do allow multiple "inheritance" of behavior . 接口确实允许行为的多个“继承”。 What Java does not support is multiple inheritance of state . Java不支持状态的多重继承。 An interface does not have state. 接口没有状态。

You can implement one or more interfaces (implement multiple behaviors) but only extend one class, abstract or not (inherit your state from one other class). 您可以实现一个或多个接口(实现多种行为),但只能扩展一个类,无论是否抽象(从另一类继承您的状态)。

Therefore it could be say that Java has "limited" support for multiple inheritance, but it's not multiple inheritance as it is canonically defined. 因此,可以说Java对多重继承有“有限”的支持,但是它不是多重继承,因为它是规范定义的。

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

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