When should you use multiple inheritance?

Answers were Sorted based on User's Feedback



When should you use multiple inheritance?..

Answer / munendra kumar

There are three acceptable answers: "Never," "Rarely," and "When the problem domain cannot be accurately modeled any other way."

There are some famous C++ pundits and luminaries who disagree with that third answer, but I will accept it.

Let's digress to consider this issue lest your interview turn into a religious debate. Consider an Asset class, Building class, Vehicle class, and CompanyCar class. All company cars are vehicles. Some company cars are assets because the organizations own them. Others might be leased. Not all assets are vehicles. Money accounts are assets. Real estate holdings are assets. Some real estate holdings are buildings. Not all buildings are assets. Ad infinitum. When you diagram these relationships, it becomes apparent that multiple inheritance is a likely and intuitive way to model this common problem domain. The applicant should understand, however, that multiple inheritance, like a chainsaw, is a useful tool that has its perils, needs respect, and is best avoided except when nothing else will do.

Is This Answer Correct ?    0 Yes 0 No

When should you use multiple inheritance?..

Answer / neelam saini

There are three acceptable answers:- "Never," "Rarely," and "When the problem domain cannot be accurately modeled any other way."

Consider an Asset class, Building class, Vehicle class, and CompanyCar class. All company cars are vehicles. Some company cars are assets because the organizations own them. Others might be leased. Not all assets are vehicles. Money accounts are assets. Real estate holdings are assets. Some real estate holdings are buildings. Not all buildings are assets. Ad infinitum. When you diagram these relationships, it becomes apparent that multiple inheritance is a likely and intuitive way to model this common problem domain. The applicant should understand, however, that multiple inheritance, like a chainsaw, is a useful tool that has its perils, needs respect, and is best avoided except when nothing else will do.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

When can you tell that a memory leak will occur?

1 Answers  


Explain shallow copy?

0 Answers  


Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.

0 Answers  


Why are pointers not used in c++?

0 Answers  


How do you write a function that can reverse a linked-list?

0 Answers  






What is #include iostream h in c++?

0 Answers  


What do you mean by late binding?

0 Answers  


What is :: operator in c++?

0 Answers  


How does throwing and catching exceptions differ from using setjmp and longjmp?

1 Answers  


What is an Iterator class?

1 Answers  


What is the main function c++?

0 Answers  


What is type of 'this' pointer? Explain when it is get created?

0 Answers  


Categories