Quantcast
Channel: Did Java avoid multiple inheritance here? - Software Engineering Stack Exchange
Viewing all articles
Browse latest Browse all 2

Did Java avoid multiple inheritance here?

$
0
0

I learnt that Java did not allow multiple inheritance using abstract classes for simplicity.

In java, after a good design of class hierarchy, SubType would not get into trouble of same method prototypes or same name variable, coming from both interface and abstract class as parent types, Because abstract class and interface are discovered(but not designed) based on implementation classes. I guess this is what it meant.

Here is the problem Java code, that still has multiple inheritance issue, using interface keyword:

abstract class SuperType1 {    protected int item;}interface SuperType2{    final float item=2.0;}public class SubType extends SuperType1 implements SuperType2{    public static void main(String[] args){        SubType s = new SubType();         //s.item = 2; //Compiler knows that 'item' is only mutable in 'class SuperType1', this code should not fail.    }}

So,

As per above program, What exactly does it mean to say that, Java omits multiple inheritance?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images