单选题 C++
题号 #2603623

有如下程序:
#include<iostream>
using namespace std;
class Basel
{
public:
BaseI(int D.{cout<<d;}
一Basel(){}
};
class Base2
{
public:
Base2(int D.{tout<<d;}
~Base2(){}
};
class Derived:public Basel,Base2
{
public:
Derived(int a,int b,int c,int D.:Basel(B.,Base2(A.,bl(D.,b2(C.{}
private:
int bl:
int b2:
};
int main()
{
Derived d(1,2,3,4);
return 0;
}
执行这个程序的输出结果是(  )。

进入在线模考

参考答案

D

答案解析

本题考查派生类的构造函数和析构函数,在定义一个派生类的对象时,先调用基类的构造函数,然后再执行派生类的构造函数,对象释放时,先执行派生类的析构函数,再执行基类的析构函数。本题中定义一个派生类对象时,分别调用基类的构造函数,所以分别输出21。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考