File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Multiple Inheritance ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic

Multiple Inheritance ?

raja veeramani

Joined: Apr 11, 2004
Posts: 3
I am aware that java does not support multiple inheritance. And I have heard people saying , multiple inheritance can be achieved using the concept of interface. But I am not able to understand how they are achieved using interface ? So does java really support multiple inheritance or not?
When there is a need for an interface to extend more than 2 interfaces ?
And why do we need interface first of all ?

Somewhere someone is dreaming of your smile
VP Jain
Ranch Hand

Joined: Feb 11, 2004
Posts: 81
For your question why do we need interface first of all ?
Say for example you are coding a billing application for an Internet Service
Provider.It calculates the following set of charges :
a. Joining fee
b. Monthly usage
c. Excess Consumption
Say for example you have three Classes for the calculation.
What is the objective of all these classes ?
They have to calculate something...right
So we implement a generic command interface called a Calculator interface
which will have a calculate method
and the interface will be like

and the class will be

So in order to enforce certain methods that is common to all classes we need
to implement interface.
I think u understand what for interface is used by now .
[Note :I have taken part of the example from and i give due credits to the author of the article Ricky yim]
For your second question
2. When there is a need for an interface to extend more than 2 interfaces ?
I would like to take up the Marker interface example for your second question
By the way a marker interface is an interface that doesn't actually define any fields.
It is just used to "mark" Java classes which support a certain capability --
the class marks itself as implementing the interface. For example, the java.lang.Cloneable interface.

The following example has three interface contract,Abelian,TypeSafeEnum and a class AddrType which implements
the TypeSafeEnum interface. The overall objective of this example is
when u compile and generate the javadoc it will emphasize on following the

"equals()","hashcode()" and "toString()" java contracts.

If you note the TypeSafeEnum interface extends the Contract,Abelian interfaces
[Note : I had taken this example from from
Maximize your Design ROI with Marker Interfaces and JavaDoc
By Bruce Wallace and i give due credit to the author]

I hope i clarified both your doubts

Added some code tags - Barry
[ April 12, 2004: Message edited by: Barry Gaunt ]

SCJP SCWCD SCBCD <br /> <br />what u do in life echos in eternity!
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
This is a duplicate post.
Round these parts, posting the same question in multiple forums is bad practice. It can make it rather difficult to follow a conversation, plus folks spend time saying things that were just said.
Let's continue this in the Beginners forum...

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Multiple Inheritance ?
It's not a secret anymore!