0
public class A {  // Extends from `Object` class
}

class B extends A { // Extends from `A`
}

class C extends B { // Extends from `B`
}

Is that considered Multiple Inheritance Or Not ?

  • 3
    Multiple inheritance is when a class inherits from more than one superclass. You should have search on Google. Even wikipedia has a dedicated page on this come on http://en.wikipedia.org/wiki/Multiple_inheritance – janos Jun 23 '13 at 20:54
  • btw This might be useful: [How do Java Interfaces simulate multiple inheritance?](http://stackoverflow.com/questions/3556652/how-do-java-interfaces-simulate-multiple-inheritance) – informatik01 Jun 23 '13 at 21:01

6 Answers6

3

No. That's just two instances of ordinary inheritance. Multiple inheritance would be something like

class A{
}

class B{
}

class C extends A, B{
}

However, this is not something that can be done in Java; inheriting from more than one base is not allowed, though interfaces allow most of the benefits it would have.

Billy Mailman
  • 272
  • 11
  • 25
2

no. this is inheritance tree. You won't find any example in Java for multiple inheritance because it is not supported

stdcall
  • 27,613
  • 18
  • 81
  • 125
1

Answer NO.

In java only exist simple-inheritance.

public class A {  // Extends from `Object` class
}

class B extends A { // Extends from `A`
}

class C extends B { // Extends from `B`
}

What you have here is

C is a B , B is a A , A is an Object

(C is A by transitivity)

Multiple inheritance would be

C is a B and also is a D, D is an object, B is a A , A is an Object

In java is not allowed multiple inheritance (having more than one parent).

What you can do is implements multiple interfaces and there you can have a kind of multiple inheritance.

nachokk
  • 14,363
  • 4
  • 24
  • 53
1

Multiple Inheritance is what you see in Python's:

class A(B,C,D,E,Infinity):

Where "A" inherits from all those classes at once. So the answer is no, because that's not what you're doing.

Ericson Willians
  • 7,606
  • 11
  • 63
  • 114
1

No you can't, as @Reimeus says.

Multiple inheritance would look like:

class A extends B, C, D, E

That is allowed in C++ but not in Java. You can have multiple interfaces, but not extend multiple classes.

rossum
  • 15,344
  • 1
  • 24
  • 38
0

No this is not considered multiple inheritance. The class hierarchy that you describe is, in fact, single inheritance as each of your classes inherit from only one other class.

Multiple inheritance occurs where a single class inherits from more than one class at the same time but this is a language feature that is not available in the Java programming language. Although it is available in other languages such as C++. By not permitting multiple inheritance that Java language designers are seeking to avoid the diamond problem associated with multiple inheritance.

It is possible for a Java class to implement multiple interfaces.

Rob Kielty
  • 7,958
  • 8
  • 39
  • 51