为什么 Java 允许从接口而不是从抽象/具体类的多重继承 [英] Why does Java allow multiple inheritance from interfaces but not from abstract/concrete classes

查看:24
本文介绍了为什么 Java 允许从接口而不是从抽象/具体类的多重继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
为什么Java中没有多重继承, 但允许实现多个接口

为什么Java允许从接口而不是抽象或具体类的多重继承

Why Java allows multiple inheritance from interfaces but not from abstract or concrete classes

推荐答案

具体类的多重继承引发了 各种问题.

Multiple inheritance of concrete classes raises a variety of issues.

例如,如果一个类从两个不同的基类继承同一个方法的两个不同实现怎么办?

For example, what if a class inherits two different implementations of the same method from two different base classes?

为避免这些问题,Java 不支持此功能.
与具体类不同,接口不能有方法体.

To avoid these issues, Java doesn't support this feature.
Unlike concrete classes, interfaces cannot have method bodies.

因此,这些问题都不适用于接口.

Therefore, none of these issues apply to interfaces.

这篇关于为什么 Java 允许从接口而不是从抽象/具体类的多重继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆