单选题 有如下程序: #inc1ude<iostream> using namespace std; c1ass Base{ public: virtual void Show(){cout<<'B';} }; c1ass Derived: public Base{ public: void Show(){ cout<<;D';} }; int main(){ Base *p1=new Derived; Derived *p2=new Derived; p1—>S1:tow(); p2—>Show(); delete p1; delete p2; retum0; } 运行这个程序的输出结果是( )。
【正确答案】 D
【答案解析】解析:在基类Base中定义了虚函数Show()输出字符‘B’,而在派生类Derived中对虚函数Show()进行了重新定义,输出字符‘D’。在主函数中对基类和派生类中的虚函数Show0进行了多态调用,此时调用的是派生类中重新定义的Show(),输出字符‘D’。