Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java does not support multiple inheritance...?

 
Som s
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends can anyone explain me how Java does not support multiple inheritance?

If a class inherits properties of more than one class then it is called multiple inheritance.

In Java, all classes extends Object class implicitly. Condsider a class B which extends class A. Here class B implicitly extends Object class. In this scenario class B inherit the properties of both class A as well as class Object, so this should be considered as multiple inheritance but we consider that java does not support multiple inheritance, why...?

-Som
 
Henry Wong
author
Marshal
Pie
Posts: 22111
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java, all classes extends Object class implicitly. Condsider a class B which extends class A. Here class B implicitly extends Object class. In this scenario class B inherit the properties of both class A as well as class Object, so this should be considered as multiple inheritance but we consider that java does not support multiple inheritance, why...?


The definition of multiple inheritance is the ability to inherit from multiple classes (from different hierachies). For example, if class B extends from class A, and class C extends from class A. Mulitple inheritance is the ability to inherit from both class B and C.

Henry
 
Rupert matthews
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In Java, all classes extends Object class implicitly. Condsider a class B which extends class A. Here class B implicitly extends Object class. In this scenario class B inherit the properties of both class A as well as class Object, so this should be considered as multiple inheritance but we consider that java does not support multiple inheritance, why...?


I think the difference is java doesn't support mulitple inheritance "explicitly." Like in c++ a class of the following can work..

class c extends A, B
()
{}

but this doesn't work in Java. Although class C is implicitly the subclass of its superclass class A, in other scenarios of "classing", it will not work.

Interface is the counterpart of inheritance in Java so we can still use the properties of the superclass of our class program.
 
Campbell Ritchie
Sheriff
Posts: 51405
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably best to say that interfaces mimic multiple inheritance, and A----->B----->C is called single inheritance.

It would only be multiple inheritance if you could draw a diagram like this
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic