top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the diamond problem in context of Java and OOPS?

+2 votes
456 views
What is the diamond problem in context of Java and OOPS?
posted Mar 20, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Suppose we have 2 classes B and C that derive from the same class – in below example:

enter image description here

it would be class A. We also have class D that derives from both B and C by using multiple inheritance. You can see in the figure above that the classes essentially form the shape of a diamond – which is why this problem is called the diamond problem. Now, let’s take the graphic above and make it more concrete by translating it into actual code:

/*
The Animal class below corresponds to class 
A in our graphic above
*/

class Animal { /* ... */ }; // base class
{
int weight;

public:

int getWeight() { return weight;};

};

class Tiger : public Animal { /* ... */ };

class Lion : public Animal { /* ... */ }    

class Liger : public Tiger, public Lion { /* ... */ };  
answer Mar 22, 2015 by Amit Kumar Pandey
...