问题 单项选择题

有如下程序:
#include < iostream >
using namespaee std;
class Basel

public :
Basel(int d) cout <<d;
~Basel ()
;
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(e)
private :
int b1 ;
int b2 ;
;
int main()

Derived d(1,2,3,4) ;
return 0 ;

执行这个程序的输出记过是( )。

A) 1234
B) 2134

C) 12

D) 21

答案

参考答案:D

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

单项选择题
问答题 简答题