Yes, C++ does support the use of multiple inheritance – where a class is derived frommore 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 { /* ... */ };
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
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.
Would you like to thankProgrammerInterview.com for being a helpful free resource?Then why not tell a friend about us, orsimply add a link to this page from your webpage using the HTML below.
Link to this page:
Please bookmark with social media, your votes are noticed and appreciated: