ProgrammingHardGATE CS · TCS NQT Prime · Product Company SDE

Why did Java and C# choose single inheritance of classes plus multiple inheritance of interfaces, instead of C++-style full multiple inheritance of classes?

  1. A. Because Java does not support any form of inheritance
  2. B. To avoid the diamond problem's ambiguity over which base class's state or implementation to use, while still allowing a type to satisfy several behavioural contracts via interfaces
  3. C. Because full multiple class inheritance was patented by another company
  4. D. Because interface method calls execute faster than class method calls

Correct answer: B. To avoid the diamond problem's ambiguity over which base class's state or implementation to use, while still allowing a type to satisfy several behavioural contracts via interfaces

Multiple inheritance of implementation creates ambiguity over shared state and conflicting method bodies (the diamond problem); interfaces side-step this because they (traditionally) carry no state.

More OOP with C++ and Java questions

Exams that ask this topic