界面是否解决了“致命的死亡钻石”?问题? [英] Do interfaces solve the "deadly diamond of death" issue?

查看:137
本文介绍了界面是否解决了“致命的死亡钻石”?问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

界面是否解决了 致命的死亡钻石 问题?

Do interfaces solve the deadly diamond of death problem?

我不这么认为,例如:

// A class implementing two interfaces Interface1 and Interface2.
// Interface1 has int x=10 and Interface2 has int x = 20

public class MultipleInterface implements Interface1, Interface2{

    public void getX(){
        System.out.println(x);
    }
}

这里我们得到一个含糊不清的 x

Here we get an ambiguous x.

虽然接口是解决方法模糊性的好方法,但我猜它们在变量的情况下会失败吗?

Though interfaces are a good way for solving method ambiguity, I guess they fail in the case of variables?

我说错了吗?如果我遗漏了一些东西,请启发我。

Am I correct? If I am missing something, enlighten me.

推荐答案

Java拒绝多个Concrete / abstract类继承但不支持多个接口继承继承抽象方法没有实现更好的帖子和良好的解释和例子 http:// www .tech-knowledgy.com / interfaces-sovles-diamond-death /

Java resists the multiple Concrete/abstract class inheritance but not multiple interface inheritance where you inherit abstract methods not implementation the better post with good explaination and examples http://www.tech-knowledgy.com/interfaces-sovles-diamond-death/

这篇关于界面是否解决了“致命的死亡钻石”?问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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