Wednesday, March 28, 2012

why java does not support multiple inheritance

Java supports multiple inheritence indirectly through the
use of interface. In case we are able to extend more than
one class then there would be a confusion of which method to
process in case both classes have same method name(Same
method signature also). 

In case of using interfaces to support multiple inheritance
we escape this problem as we define the methods that are
needed only.
 
Q. You can create an abstract class that contains only abstract methods.
 On the other hand, you can create an interface that declares the same 
methods. So can you use abstract classes instead of interfaces?

A. Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.
 

No comments:

Post a Comment