To determine the expected output, let’s analyze the code step by step:
Key Observations
- Virtual Function in Base Class: The
Baseclass defines avirtual void show()method. This enables dynamic polymorphism (runtime method resolution). - Derived Class Override: The
Derivedclass inherits fromBaseand redefinesshow()with the same signature. Since the base method isvirtual, this is a valid override. - Polymorphic Call: In
main(), aBase*pointer points to aDerivedobject. Whenptr->show()is called, the runtime system checks the actual type of the object (not the pointer type) and invokes theDerivedclass’sshow()method.
Output
The Derived class’s show() method prints "Derived".
Answer: Derived
\boxed{Derived}
作者声明:本文包含人工智能生成内容。