有如下程序: #include using namespace std; class TestClass l { public: virtual void fun(){cout

admin2020-06-29  14

问题 有如下程序:
    #include
    using namespace std;
    class TestClass l
    {
    public:
    virtual void fun(){cout<<“l”;)
    };
    class TestClass2:public TestClass 1
    {
    public:
    TestClass20{cout<<”2”;)
    };
    class TestClass3:publ

选项 A、1122
B、2112
C、2213
D、2223

答案C

解析 主函数中定义TestClassl的对象aa,木p对象指针,TestClass2的对象bb以及TestClass3的对象cc。p指向cc,TestClass3为TestClass2的派生类,构造函数输出2。TestClass3中fun函数中为TestClass2中的fun,调用TestClass2的构造函数,输出2。“p一>fun();”,TestClass2继承于TestClassl中的fun,所以输出1。然后输出TestClass3中的“cout<<”3””,即输出3。
转载请注明原文地址:https://kaotiyun.com/show/lO8p777K
0

相关试题推荐
最新回复(0)