why we use an interface?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   bhagavan_t
Posted On:   Thursday, August 9, 2007 03:16 PM



why we are using the interface reference to the class objects

that are implemented by the interface.

Re: why we use an interface?

Posted By:   Ranjith_S  
Posted On:   Wednesday, August 29, 2007 11:24 AM

In C++, we can use Multiple Inheritance. But in java, we can only use Multi-Level Inheritance rather than Multiple Inheritance. So that we go for Interface concept.

Multiple Inheritance:
eg:
class one{
}
class two{
}
class three extends one,two{

}

Multi-Level Inheritance:
eg:
class one{
}
class two extends one{
}
class three extends two{
}

Re: why we use an interface?

Posted By:   Anonymous  
Posted On:   Friday, August 10, 2007 02:13 AM



In java the interface is used to fulfill the concept of Multiple Inheritance.

Multiple Inheritance-
Here if we have two classes A & B having a method
'id()' in both classes and we have another class C which inherits both A & B to use 'id()' in C.

Then the JVM is in confusion to use which class
variable.That's why we don't have multiple inheritance in java.

Interface
In interface we don't have any implementations.And we can't create objects to interfaces.So we create a refernce
to interface and points to the objects of classes by which
that interface is implemented and call the method.

So here there is no confusion to JVM.

About | Sitemap | Contact