Question 71
HardWhat is the fragile base class problem?
- A.
Base classes being deleted
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
What is the fragile base class problem?
Base classes being deleted
Seemingly safe changes to a base class break subclasses that depend on its internal behaviour
Base classes being too small
Subclasses that can't be created
Sign up free to see the answer and a step-by-step explanation.
Why is 'favour composition over inheritance' good advice?
Inheritance can't reuse code
Composition couples classes less tightly and lets behaviour change at run time
Composition is faster to compile
Inheritance is never allowed
Sign up free to see the answer and a step-by-step explanation.
What is a mixin?
A constructor
A class that adds a specific capability to others through multiple inheritance, not meant to stand alone
A singleton
An abstract factory
Sign up free to see the answer and a step-by-step explanation.
In Python, what does D.mro give for class D(B, C) where B and C both inherit from A?
(D, B, A, C, object)
(D, C, B, A, object)
(D, B, C, A, object)
(D, A, B, C, object)
Sign up free to see the answer and a step-by-step explanation.
Which call refers to the parent's version of an overridden method in C++?
parent->method()
Base::method()
this->Base()
super.method()
Sign up free to see the answer and a step-by-step explanation.
A subclass method in Java has the same name as a parent's private method. What is it?
A new, unrelated method; private methods aren't inherited or overridden
An overload
An override
A compile error
Sign up free to see the answer and a step-by-step explanation.
Which is a sign that inheritance is being misused?
A subclass calls super()
A subclass overrides toString()
A subclass adds new methods
A subclass throws UnsupportedOperationException for inherited methods
Sign up free to see the answer and a step-by-step explanation.
What does the 'protected' access modifier risk in a library's public base class?
Subclasses everywhere may rely on protected members, so changing them breaks client code
It makes members public
It hides members from subclasses
Nothing
Sign up free to see the answer and a step-by-step explanation.
In C++, when a derived class declares a function with the same name as a base-class overload set, what happens to the other base overloads?
They become virtual
They cause a compile error
They remain visible
They are hidden unless brought in with a using-declaration
Sign up free to see the answer and a step-by-step explanation.
What is the order of constructor calls for class C : public A, public B?
A, then B, then C (the order in the base list)
B, A, C
C, A, B
C, B, A
Sign up free to see the answer and a step-by-step explanation.