Object-Oriented Programming · Question 9 · Medium
In C++, how is the "diamond problem" (two copies of a common base class through multiple inheritance) avoided?
- Friend functions
- Operator overloading
- Templates
- Virtual inheritance
Answer and explanation
Answer: D. Virtual inheritance
Explanation: Declaring the intermediate classes with virtual inheritance (class B : virtual public A) makes the most-derived class share a single subobject of A.
Previous: Which statement about abstract classes and interfaces in Java is correct? · Next: Which pair of method declarations CANNOT both appear in the same Java class?
Practise object-oriented programming
Try a fresh set of object-oriented programming questions with an explanation after every answer, free and without signing up: Object-Oriented Programming practice. Or sit a full placement mock test.
More object-oriented programming questions
- What is the output of the following Java code?
- What is the output of the following Java code?
- Which statement about abstract classes and interfaces in Java is correct?
- Which pair of method declarations CANNOT both appear in the same Java class?
- What is printed when new C() is executed?
- What is the output of the following Java code?
- What is the output of the following Java code?
- What is the output of the following Java code?
- Which SOLID principle states that objects of a subclass should be usable…
- A Logger class keeps a list of log entries in a private field and offers only…
More technical & programming practice
DBMS · SQL · Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps · GenAI Basics · Pseudo-code
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge