Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Multiple Inheritance

  Asked By: Clifton    Date: Apr 29    Category: Java    Views: 962
  

This may be a dumb question.Is below scenario similar to multiple
inheritance ?

Class B extends Class A
Class C extends Class B

Then isn't it similar to Class C extends Class A & B.Is it any
different ?.

Share: 

 

13 Answers Found

 
Answer #1    Answered By: Cais Nguyen     Answered On: Apr 29

No - C extends B. B extends A. This is a single inheritance
hierarchy. Java only supports single inheritance.

Multiple inheritance  is where a class  inherits from two (or more)
classes from different hierarchies. A popular example is a pencil
with an eraser - if multiple  inheritance was available the qustion
was should you create a new class that inherits from both Class
Pencil and Class Eraser. The answer is that a pencil with an eraser
on the end is a subclass of pencil that 'has a' eraser.

Multiple-inheritance has been deprecated in OO circles for a long
time. In Java you can use interfaces i.e a pencil that has an eraser
would implement both the pencil and eraser interface.

 
Answer #2    Answered By: Jaspreet Kapoor     Answered On: Apr 29

Multiple inheritance  refers to
class C extends A, B
Where A and B are not related. This cannot be done in Java.
(Note that Java Interfaces can have multiple  inheritance, for example
interface C extends A, B
(Where A and B are interfaces)

 
Answer #3    Answered By: Elaine Stevens     Answered On: Apr 29

IMHO the term "multiple inheritance" in the java documentations should
be re written as "multiple inheritance  on a single level is not allowed
in java"

There is multiple  inheritance on various levels of the class  hierarchy
since we can say that the class C has both the properties of class A
and Class B
eg . Class B extends Class A
Class C extends Class B

Where else with respect to an example like
class B extends Class A, Class B
This represents multiple inheritance on a single level and this is not
allowed in java

 
Answer #4    Answered By: Alexis Castillo     Answered On: Apr 29

The term multiple  inheritance is accepted to mean:

class A extends B, C

Extending from a class  which extends from another class is not multiple
inheritance.

 
Answer #5    Answered By: Dot net Sachin     Answered On: Apr 29

But you can have multiple  interfaces though.

 
Answer #6    Answered By: Renee Lane     Answered On: Apr 29

Yes....................................

 
Answer #7    Answered By: Volney Fischer     Answered On: Apr 29

d> This may be a dumb  question.Is below scenario  similar to multiple
d> inheritance  ?

d> class  B extends Class A
d> Class C extends Class B

d> Then isn't it similar to Class C extends Class A & B.Is it any
d> different ?.

that doesnt really help you

use this

class C extends A implements B
{

}

it means the super() call calls on class A, but if i am not mistaken
doesnt call the constructor of B.

 
Answer #8    Answered By: Sophie Campbell     Answered On: Apr 29

class  cannot extend an interface they can only implement interfaces.
Interfaces on the other hand can extend from multiple  enterfaces but
interfaces cannot implement another interface.

Thus, in the code you have provided A must be a class and B must be an
interface and therefore B would have no constructor.

IMHO the original question  should be answered with another question:
what are you trying to do? Java doesn't have multiple inheritence but
in most cases it is not necessary since you can achieve similar results
using interfaces.

 
Answer #9    Answered By: Adalwine Fischer     Answered On: Apr 29

All java classes extends Object class.If we define custom
class which which extends another class  say HttpServlet. Thus the
custom class is extending two classes.Pls explain whats' wrong????

 
Answer #10    Answered By: Kristin Johnston     Answered On: Apr 29

you can't extend it, because java does not support the multi'inherit,
you use only the interface.

 
Answer #11    Answered By: Beatriz Silva     Answered On: Apr 29

the custom class  is not extending 2 classes ,
your base class is extending the Object class , your
custom class extends the base class

 
Answer #12    Answered By: Yvonne Watkins     Answered On: Apr 29

In other words, what you have here is an Inheritance tree, NOT Multiple
Inheritance.

Object
|
|
\|/
HttpServlet
|
|
\|/
Custom Class

In Java, each class  may directly inherit from only 1 other class, but
may inherit indirectly from as many classes as necessary. All classes
inherit from Object, either directly or indirectly. Your Custom Class
inherits from HttpServlet directly and Object indirectly.

 
Answer #13    Answered By: Yvette Griffin     Answered On: Apr 29

The point is correct. But in this case the JVM takes care of it.
For more details one can refer "Inside JVM" book. Java rules some
times good for programmer but not for JVM. Another good example is EJB.

 
Didn't find what you were looking for? Find more on Multiple Inheritance Or get search suggestion and latest updates.




Tagged: