Multiple inheritance

how to implement multiple inheritance in java
[52 byte] By [nidhi3019a] at [2007-11-27 2:35:11]
# 1
There is no multiple inheritence in Java but you can use interfaces : http://java.sun.com/docs/books/tutorial/java/IandI/index.htmlFor more inforamtion: http://www.javaworld.com/javaqa/2002-07/02-qa-0719-multinheritance.htmlhope that helps
java_2006a at 2007-7-12 2:53:18 > top of Java-index,Java Essentials,New To Java...
# 2
so many time this question have been answered.so many times this question have created problems.one might wonder how many times will you ask the same question again and again?i am also lost in my questionDukes please..Message was edited by:
lrngjavaa at 2007-7-12 2:53:18 > top of Java-index,Java Essentials,New To Java...
# 3
by using interfaces. you're probably thinking of inheriting from multiple classes, but you can't do that in java, nor is it a particularly good idea in most cases anyway
georgemca at 2007-7-12 2:53:18 > top of Java-index,Java Essentials,New To Java...
# 4

you can't implement multiple inheritance in java

and as georgemc said it can only be done through interfaces or attain ur results using single inheritance eg: if A,B class are inherited by C classthen what u can do is

class A

// body

class B extends A

// body

class C extends B

// body

that way u will be able to inherit the features of A & B in C.

gaurav_xmla at 2007-7-12 2:53:18 > top of Java-index,Java Essentials,New To Java...
# 5

> how to implement multiple inheritance in java

Multiple inheritance of type is in the language so you just start using it.

Java has single inheritance of implementation so if you want multiple inheritance of implementation you have to simulate it using an interface for the type and a delegated class for the implementation.

gaurav_xmla at 2007-7-12 2:53:18 > top of Java-index,Java Essentials,New To Java...
# 6
Java HAS multiple inheritance, but only for interfaces:one interface can EXTEND several other interfacesbut one class can EXTEND only one other class but IMPLEMENT several interfaces-Puce
Pucea at 2007-7-12 2:53:18 > top of Java-index,Java Essentials,New To Java...
# 7
> Java HAS multiple inheritance, but only for> interfaces:That's not true. The Java multiple inheritance of type is not restricted to interfaces only. Also classes and enums can inherit as many interfaces as they like.
Pucea at 2007-7-12 2:53:18 > top of Java-index,Java Essentials,New To Java...
# 8
Not with the "extend" keyword, only with the "implements" keyword. But an interface can EXTEND several interfaces but implement none. Read my last post again.
Pucea at 2007-7-12 2:53:18 > top of Java-index,Java Essentials,New To Java...
# 9
> Not with the "extend" keyword, only with the> "implements" keyword. But an interface can EXTEND> several interfaces but implement none. Read my last> post again.Well, okay I guess I maybe misread your post. -:)
Pucea at 2007-7-12 2:53:18 > top of Java-index,Java Essentials,New To Java...
# 10
Ahh, the OP pulled the Indian Ropetrick. Question asked, suckers reply, home assignment accomplished, vanish without a trace.My god why do I never learn -:)
Pucea at 2007-7-12 2:53:18 > top of Java-index,Java Essentials,New To Java...
# 11

> Not with the "extend" keyword, only with the

> "implements" keyword. But an interface can EXTEND

> several interfaces but implement none. Read my last

> post again.

Which word you use is irrelevant. extends and implements really mean the same thing--"inherits from". It's just that in certain situations only one is legal and in other situations only the other is legal. It's not like you go around deciding "Hmmm, should I use extends or implements? If I use extends, I'll only be able to inherit once."

jverda at 2007-7-12 2:53:18 > top of Java-index,Java Essentials,New To Java...
# 12
> Which word you use is irrelevant.No it's not and I think Puce has it right here actually.
jverda at 2007-7-12 2:53:19 > top of Java-index,Java Essentials,New To Java...
# 13

> > Which word you use is irrelevant.

>

> No it's not and I think Puce has it right here

> actually.

Nothing he's said is incorrect. He just seems to be putting too much weight on the specific word used to express the inheritance, when that's not relevant here.

jverda at 2007-7-12 2:53:19 > top of Java-index,Java Essentials,New To Java...
# 14

Well, as far as I can remember the UML terms, classes don't inherit from interfaces, they implement them. Classes inherit from classes and interfaces inherit from interfaces. In these terms multiple inheritence in Java does only exist for interfaces.

But I agree, that you don't have a choice to use either the extends or the implements keyword once the type (interface or class) is fixed. And the instanceof operator does not destinguish between 'implements' and 'extends' either.

But consider this comment only as a side note. Maybe I was just working up the fact that you actually can have a comma separated list of types after the extends keyword, when I thought for such a long time you can not. Though this is only true for interfaces extending interfaces, which makes perfect sense. :-)

Have a nice evening!

-Puce

Pucea at 2007-7-12 2:53:19 > top of Java-index,Java Essentials,New To Java...