ProgrammingVery hardHCL · Tech Mahindra pattern

What is printed?

What is printed?
class Base {
public:
    void info() { cout << "Base::info "; helper(); }
    void helper() { cout << "Base::helper"; }
};
class Derived : public Base {
public:
    void helper() { cout << "Derived::helper"; }
};
int main() {
    Derived d;
    d.info();
}
  1. A. Base::info Derived::helper
  2. B. Base::info Base::helper
  3. C. Derived::info Derived::helper
  4. D. Compilation error: helper redefinition requires override

Correct answer: B. Base::info Base::helper

Neither info() nor helper() is virtual, so even though info() is called on a Derived object, the unqualified call to helper() inside Base::info resolves at compile time to Base::helper (the one visible in Base's own scope), not Derived::helper.

More OOP with C++ and Java questions

Exams that ask this topic