首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class Base1 { public: Base1(int d) { cout
有如下程序: #include using namespace std; class Base1 { public: Base1(int d) { cout
admin
2021-05-06
43
问题
有如下程序:
#include
using namespace std;
class Base1
{
public:
Base1(int d) { cout<
~Base1() { }
};
class Base2
{
public:
Base2(int d) { cout<
~Base2() { }
};
class Derived : public Base1,Base2
{
public:
Derived(int a,int b, int c, int d):Base1(b), Base2(a), b1(d), b2(c) { }
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。
转载请注明原文地址:https://www.kaotiyun.com/show/xHfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下类定义classAnimal{public:virtualvoidName0=0;};classKoala:publicAnimal{public:voidName(){/*函数体略*/}};关于上述类定义,下列描述中错
有如下类定义:c1assAA{inta;public:intgetRef()const{retum&a;}//①intgetValue()const{retuma;}
有如下程序:#includeusingnamespacestd;classGA{public;virtualhatf(){retum1;}};classGB:pub
有如下程序:#include<iostream>usingnamespacestd;classMyClass{public:MyClass(){++count;}~MyClass(){--c
有如下程序:#includeusingnamespacestd;intmain(){charstr[100],*p;cout
下列程序将x、y和z按从小到大的顺序排列,横线处应添加语句()。template<classT>voidfun(____){Ta;if(x>y){a=x;x=y;y=a;}if(y
有如下程序:#inc1ude<iostream>usingnamespacestd;c1assMyClass{public:MyClass(){cout<<’*’;}M
随机试题
呼吸道分泌液中,主要的抗病毒和抗细菌的免疫球蛋白是
用于水泥混凝土的砂,应对()有害杂质有所控制。
社会主义市场经济除具有一般市场经济的特征外,还具有()等基本特征。
我国工程项目基本建设包括:①编制计划任务书、选定建设地点;②初步设计,经批准列入国家年度计划后组织施工;③经批准后,进行勘察设计;④工程按设计建成,进行验收、交付使用,则正确的建设程序是()。
金融工具的基本分析方法包括()。
《税务代理业务规程》规定,代理人可以接受纳税人、扣缴义务人的委托,从事规定范围内的业务代理,下列代理可接受的有()。
根据下列资料,回答下列问题。2014年1—3月全国固定资产投资与2015年1—3月全国固定资产投资相比,同比增速之差为:
Ah,thenaivetyoftheoldergeneration.Nearly500eminentastronomers,biologists,chemists,physicistsandearthscientistsh
下列关于RPR技术的描述中,错误的是()。
BillGates,thebillionaireMicrosoftchairmanwithoutasingleearneduniversitydegree,isbyhissuccessraisingnewdoubtsa
最新回复
(
0
)