Search code examples
javaphpoopinheritancemultiple-inheritance

Are there languages that support Multiple Inheritance of two or more Classes?


I know that PHP and Java don't allow to do that. I guess that other languages don't allow to do like that too. But why? I think that it would be quite useful.

Here's code (it's not correct syntax for any language) that explains what I meant...

class X extends Y, Z {

}

If it would be possible, class X would have all fields and methods that Y and Z have.


Solution

  • C++ allows multiple inheritance.

    You can read a full description of this feature here in an article by Bjarne Stroustrup, the creator of C++.

    But it's not the silver bullet to all of your problems. Multiple inheritance generally creates more problems than it solves. Perhaps you could get better suggestions if you posted a question explaining what you were trying to achieve in the language of your choice?

    I certainly would not suggest learning C++ just to take advantage of multiple inheritance.