为什么Java中没有多重继承,但允许实现多个接口? [英] Why is there no multiple inheritance in Java, but implementing multiple interfaces is allowed?

查看:28
本文介绍了为什么Java中没有多重继承,但允许实现多个接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 不允许多重继承,但它允许实现多个接口.为什么?

Java doesn't allow multiple inheritance, but it allows implementing multiple interfaces. Why?

推荐答案

因为接口只指定类正在做什么,而不是如何做它.

Because interfaces specify only what the class is doing, not how it is doing it.

多重继承的问题在于两个类可能定义了不同的方式来做同样的事情,而子类无法选择选择哪一个.

The problem with multiple inheritance is that two classes may define different ways of doing the same thing, and the subclass can't choose which one to pick.

这篇关于为什么Java中没有多重继承,但允许实现多个接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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