Have you ever heard about Diamond Problem in java...♦♦???
Yes I'm sure you are , if you have ever come across with Object Oriented Concepts applying in Java. Consideration of the Diamond Problem comes with one of the popular concepts of OOP which is called as the "Inheritance" in Java.
Don't worry if you are new to this and never heard about Diamond Problem. Let's start now..
What is Diamond Problem?
Diamond Problem is sometimes referred as the "Deadly Diamond of Death".
Simply it is an ambiguity that arises when two classes (class B , class C) inherit from a class (class A) and another class (class D) inherits from both B and C.
Have a look at this example if you still didn't get it..
Let's assume that Super class A is an abstract class and class B ,C and D are concrete classes.
Note:
Abstract class : Base class or a Super class where only declared abstract methods and which does not provide implementations for all of its methods.
Concrete class : Derived class that provides the basic implementations for all of the methods that are not already implemented in the super class.
Here the ambiguity arises in class D when it tries to call Close() method. The compiler doesn't know from which class does it inherit as shown in the figure.
This is a serious problem for some other popular OOP languages like C++ that allows multiple inheritance while java doesn't allow multiple inheritance in classes.
Note:
Multiple Inheritance : Where class can inherit from more than one class
Consider the following situation related to above example.
Class_A.java
No comments:
Post a Comment