有如下程序: #include using namespaee std; class Base{ int x; public: Base(int n=0):x(n){eout

admin2015-07-24  26

问题 有如下程序:
    #include
    using namespaee std;
    class Base{
    int x;
    public:
    Base(int n=0):x(n){eout<    int getX()eonst{return x;}
    };
    class Derived:public Base{
    int y;  
    public:
    Derived(int m,int n):y(m),Base(n){eout<    Derived(int m):y(m){eout<    };   
    int main()
    {
    Derived d1(3),a2(5,7);
    return 0;
    }
    执行这个程序的输出结果是(    )。

选项 A、375
B、357
C、0375
D、0357

答案C

解析 本题考查派生类的构造函数和析构函数,在定义一个派生类的对象时,先调用基类的构造函数,然后再执行派生类的构造函数,对象释放时,先执行派生类的析构函数,再执行基类的析构函数。本题中定义了一个对象d1,先执行基类的构造函数输出O,再执行派生类的构造函数输出3,然后定义了一个对象d2(5,7),其中需要调用基类的构造函数输出7,最后输出5,所以答案为C。
转载请注明原文地址:https://jikaoti.com/ti/DQE0FFFM
0

最新回复(0)