Testing C++ method override and virtual function resolution
This is an easy C++ language-knowledge question that probes your understanding of virtual functions and method override semantics. The question presents a code snippet and asks what output is produced, testing whether you can mentally trace the runtime behaviour of inheritance and polymorphism.
To answer correctly, you need to understand how the compiler resolves method calls at runtime when base and derived classes both define methods with the same signature. Key considerations include whether functions are declared virtual, whether the derived class properly overrides them, and what type the calling code actually holds (a base-class pointer or reference versus a concrete object). These distinctions determine which implementation executes.
- Virtual versus non-virtual method dispatch
- Override specifier and inheritance hierarchies
- Pointer/reference type vs. object type at runtime