单选题 有如下程序:
#include <iostream>
using namespace std;
class Base1
{
public:
Base1(int d) {cout<<d;}
~Base1(){}
};
class Base2
{
public:
Base2(int d) {cout<<d;}
~Base2(){}
};
class Derived:public Base1,Base2
{
public:
Derived(int a,int b,int c,int d):Base1(b),Base2(a),b1(d),b2(c){}
pnvate:
int b1:
int b2:
};
int main()
{
Derived d(1,2,3,4);
return 0;
}
执行这个程序的输出结果是______。
【正确答案】 D
【答案解析】[解析] 本题考查派生类的构造函数和析构函数,在定义一个派生类的对象时,先调用基类的构造函数,然后再执行派生类的构造函数,对象释放时,先执行派生类的析构函数,再执行基类的析构函数。本题中定义一个派生类对象时,分别调用基类的构造函数,所以分别输出21。