多重继承 [英] Multiple Inheritance

查看:133
本文介绍了多重继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,你开始往下投票我请仔细阅读这个问题,请大家理解,我不尝试启动任何不愉快这里之前。

Guys before you start down voting me please read this question and please understand that I do not try to start anything unpleasant here.

有关这个问题的唯一原因是说我越来越意识到,为了更加受雇我要知道无论是Java和/或C#。

The only reason for this question is that I'm becoming more and more aware of that in order to be more employable I have to know either Java and/or C#.

确定这里就是问题:

我知道,多重继承在J和C#禁止的。但是,如果我做这样的事情(因为我想有这两个类B和继承的类A):

I know that multiple inheritance is forbidden in J and C#. But if I do something like this (because I would like to have a class which inherits from two classes B and A):

//code in Java
public class B
{
    public void methodFromB()
    {
    }
}

public class A extends B
{
    public void  methodFromA()
    {
    }
}

public class C extends A
{
    public void methodFromC()
    {
    }
}

所以,事实上,据我理解这一点,我也从他们两个(A和b的继承和是的,我也明白,这个正式的解释是,对象A是一个专门b,而没有,如果我少要做到这一点我会,但它只是看起来不漂亮)

So in fact as far as I understand this, I do inherit from both of them (A and B and yes I do understand that formal explanation for this is that the object A is a specialized B but none the less if I want to do it I will but it just doesn't look pretty)

但不是在一个声明中这样做,我必须首先创建从另一个类一个类继承和然后从它派生?

But instead of doing this in one declaration I have to first create one class inherit from another class and then derive from it?

有趣的事情虽然。在宣布这些类如上(在NetBeans)我看到创建C类的一个实例(主),我不能调用methodFromC它这是在这个类中定义的方法之后。

Funny thing though. Having declared those classes as above (in NetBeans) I see that after creating an instance of class C (in main) I cannot invoke methodFromC on it which is the method defined in this class.

是什么原因呢?

感谢。

推荐答案

您多重继承的定义是不正确的

Your definition of multiple inheritance is not correct.

在OO层次,多重继承是很好,明确的规定。

At the OO level, multiple inheritance is well and clearly defined.

和C ++和Java的支持多重继承。

And both C++ and Java support multiple inheritance.

现在的问题是,大多数程序员绝对零OO / OOA / OOD的概念,所有他们知道是OOP的实现细节。因此,他们的错误信念的继承的是同义词的实现继承

The problem is that most programmers have absolutely zero OO/OOA/OOD notions and all they know are OOP implementation details. Hence their wrong belief that "inheritance" is synonym to "implementation inheritance".

然而,这是<强>完全错误

由于Java支持多个(接口)继承,这恰好是继承的真实,唯一的形式存在于面向对象-Analysis /面向对象,设计水平。

Because Java support multiple (interface) inheritance, which happens to be the real and only form of inheritance that exists at the Object-Oriented-Analysis / Object-Oriented-Design level.

显示我的任何 OOD从OOA结果,就是用多继承,我能翻译它清晰地在Java中使用多个接口继承(如Java中的额外的奖励钻石的问题不存在)OOP。

Show me any OOD resulting from an OOA and that is using multiple inheritance and I can translate it cleanly to OOP in Java using multiple interface inheritance (as an added bonus in Java the "diamond" problem doesn't exist).

这篇关于多重继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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