Does C++ support multiple inheritance?

Yes, C++ does support the use of multiple inheritance – where a class is derived from more than one direct base class. Let’s show an actual example of multiple inheritance. Suppose we have a class D, that derives from 2 classes – B and C. This is what the code would look like in order to implement multiple inheritance in C++ (assuming we have classes B and C):

class B { /* ... */ };
class C { /* ... */ };

// this is multiple inheritance:
class D : public B, public C 
{ 
/* ... */ 

};

What problems could be caused by multiple inheritance?

There is a problem known as the diamond problem that occurs when multiple inheritance is used in a certain way. You can read more about it here: Diamond Problem Explained




Does Java have multiple inheritance?

No, Java does not have multiple inheritance, but it has interfaces which can be used instead of multiple inheritance. For more information on this read here: Multiple Inheritance in Java.

Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>

Subscribe to our newsletter for more free interview questions.