单选题
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。
你可能感兴趣的试题
A.Base
Base
Base
B.Base
Derived
Derived
C.Derived
Base
Base
D.Derived
Derived
Derived
A.类模板的主要作用是生成抽象类
B.类模板实例化时,编译器将根据给出的模板实参生成一个类
C.在类模板中的数据成员都具有同样类型
D.类模板中的成员函数都没有返回值
A.cast(i);
B.cast<>(i);
C.east<char*,int>(i);
D.east<double,int>(i);