2

In Java, they say that Multiple Inheritance is not supported. Also its a fact, that each class in Java extends class Object. So if I write :

public class ThreadInstance extends Thread {
}

How does this compile? ThreadInstance here is actually extending Thread as well as Object. Isn't it multiple Inheritance here.

Gaurav Kumar
  • 1,091
  • 13
  • 31

3 Answers3

1

By multiple inheritance you should understand inheriting multiple classes at the same time, e.g. it's impossible to create a

public class ThreadInstance extends Thread, Object {
}

because class hierarchy would look like this:

ThreadInstance
^            ^
Thread       Object

When you define your ThreadInstance like you did, the ThreadInstance inherits Object too, but it first inherits thread.

ThreadInstance
      ^
    Thread
      ^
    Object

There is no multiple inheritance there.

fracz
  • 20,536
  • 18
  • 103
  • 149
0

Your class extends Thread but Thread already extends Object so it's still single-inheritance as it follows the same line of inheritance

Object is implicitly inherited by every class. In your ThreadInstance class, Thread is explicitly inherited.

Thus every Java class except Object must have a super-class. There's nothing all to special about implicit inheritance, it's simply there to reduce boilerplate code.

Juxhin
  • 5,068
  • 8
  • 29
  • 55
0

Your class that extends that other class, but it extends Object, too, so you're still in one line of inheritance, not two.

Eg. ThreadInstance extends Thread, but Thread in turn extends Object so cant I say ThreadInstance extends Object.

Saurabh Jhunjhunwala
  • 2,832
  • 3
  • 29
  • 57