GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

When should we use multiple inheritance?

asked Oct 25, 2015 by Swanky

2 Answers

We should use multiple Inheritance because it reduces the code we need to write and  increases the readability  and  with the help of multiple inheritance code maintenance also increases.

Take an example , suppose we have window class and we have draggable class now   a class which should have both above property can be made by two mechanism -

Either implement completely (no code reuse)  or  inherit one property (partial code reuse) or

we can multiply inherit both and save ourself from rewriting the code and debugging , which can be achieved with this simple statement - 

class DraggableWindow : Draggable, Window 

{//  some more user defined code }

As above class depends on two other classes, any change will reflect in this class too (easy maintenance)

   So in short , multiple inheritance is not used mostly , but class which are kind of mix classes  require multiple inheritance in action.

 

answered Oct 26, 2015 by utkarsh111

You can answer this question in three manners:

  • Never
  • Rarely
  • If you find that the problem domain cannot be accurately modeled any other way.
answered Oct 26, 2015 by Gaurav
...