Perry Smith

Java Questions & Answers

Home / Java Q & A Archive Page 3 / Java Q & A Archive

How multiple inheritance achieved in java
Friday, 05-Feb-99 02:16:37

203.129.225.221 writes:

Hello!
I want to know how multiple inheritance is achieved in java using interface. i.e. i should able to call all super class's functions
Bye
Anand Gore


Response
Re: How multiple inheritance achieved in java
Friday, 05-Feb-99 11:23:00

208.16.89.91 writes:

I don't know if this will help you, but, the following statements are from the Java Certification Exam Guide For Programmers And Developers by Barry Boone:

"The need for an interface arose because Java only has single inheritance of implementation. This means that every class has exactly one superclass. If you want to inherit behavior from two classes, you just can't do it, The reason for this restriction is purely one of eliminating complications(42)."

"Even though multiple inheritance of implementation is not allowed, a design based on multiple inheritance can be very useful(43)."

I will let someone else carry on from here.

Perry Smith


multiple inheritance of messages, not methods
Wednesday, 10-Feb-99 20:15:34

194.158.187.242 writes:

JAVA does not really support mulitple inheritance. The concept of interfaces is related to multiple inheritance, but it is not the same thing.

An interface just lists messages (the identifiers of methods), not the implementing code of methods itself. In an interface, all methods are abstract.

A class can implement an interface. The compiler will check that the class implements all methods of the interface. These methods may be defined in a normal superclass (the single-inheritance way).

When you have two unrelated classes (no common super class) implementing the same interface, requiring the same code... you will just have to copy the code, or reanalyse your class tree.

There is no way to implemend code in an interface, so there is no way to inherit that code, and so there is no way to multiple-inherit that code.

The logic behind this all is that multiple inheritance creates more problems than it solves. JAVA keeps it simple.

Henk Jan


Re: How multiple inheritance achieved in java
Saturday, 06-Mar-99 01:26:27

202.54.7.29 writes:

See, itz like this.. multiple inheritance acc. to java gurus defeats Object oriented thinking.. that's why u don't have multiple inheritance in Java.. but actually, even Java has something called adapters, which i think are a poor man's equivalent for multiple inheritance.. check that out from the tutorial and post any questions u have reg. that..

ganchu


Home / Java Q & A Archive Page 3 / Java Q & A Archive