java 多继承,Java是否支持多继承?

From the Java fact that all class in Java have a parent class as Object. But the same Java says that it doesn't support multiple inheritance. But what this code mean ?

public class A extends B

{

//Blah blah blah

}

From the above code it means that Class A extends Class B. Now Class A also have inherited the properties of Object class which is the super class of B. Is this doesn't mean that Class A have inherited both Class B and Object Class, this what we called Multiple inheritance right?

So now Java supports Multiple inheritance, if not then what is the answer for the above code(which shows multiple inheritance)

解决方案

No, this is single inheritance. A inherits from B, B inherits from Object.

Multiple inheritance would be A extends from B and C, where B and C don't inherit from each other, which can cause the Diamond Problem:

If B defines a method foo() and C also defines a method foo(), and I do this:

new A().foo();

Which foo() implementation will be used?

This is a huge problem in many languages, so the Java designers decided not to allow multiple inheritance.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值