• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mutliple inheritance in Java

 
narain ashwin
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am suspecting my understanding that JAVA doesn't support multiple inheritance

Consider this class

We can say that this class extends the Object class.But if I modify the above class to implement threading

seems like MyClass extending both Object class (implicitly) and Thread class (explicitly).Doesn't that means multiple-inheritance?
 
Roland Maurer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one java class can not be extended from more than one superclass.

class A extends B,C is not working !!

but you can do eg:

class A implements B,C,...

seems like MyClass extending both Object class (implicitly) and Thread class (explicitly).Doesn't that means multiple-inheritance?


your class extends Thread and Thread extends Object or something else ..


http://en.wikipedia.org/wiki/Multiple_inheritance


Originally posted by narain ashwin:
I am suspecting my understanding that JAVA doesn't support multiple inheritance

Consider this class

We can say that this class extends the Object class.But if I modify the above class to implement threading

seems like MyClass extending both Object class (implicitly) and Thread class (explicitly).Doesn't that means multiple-inheritance?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a class cannot DIRECTLY extend more than one class. it can only have one parent. However, it can have a grand-parent, a great-grand-parent, etc.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic