What is Multiple Inheritance???
Multiple Inheritance is a concept which allows a subclass to inherit from more than one super class.
Unlike C++ , Java does not support multiple inheritance by extending more than one superclass.
Why so????
If another Class D is allowed to extend Class B as well as Class C...
and if doWork() method is overridden both in Class B as well as Class C
From Class D, it becomes ambiguous to invoke doWork() as it had inherited two different implementations for the same.
The class hierarchy forms a diamond shape when represented by diagram and hence got its name "THE DIAMOND PROBLEM"
This problem is however solved by using Multiple Interface Inheritance..Which we will learn when we read about Interfaces..As of now we have a understanding of why multiple inheritance is not supported by JAVA..by extending more than one super class..
No comments:
Post a Comment
Got to say something?...Leave your comments here