Guys before you start down voting me please read this question and please understand that I do not try to start anything unpleasant here.
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#.
Ok here is the question:
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()
{
}
}
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?
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.
What is the reason for that?
Thanks.
Your definition of multiple inheritance is not correct.
At the OO level, multiple inheritance is well and clearly defined.
And both C++ and Java support multiple inheritance.
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”.
However this is completely wrong.
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.
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).