首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
18
问题
有如下程序:
#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://jikaoti.com/ti/HJh0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错误,请改正错误,使得程序通过运行。程序输出:5a1注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//
使用VC6打开考生文件夹下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能:(1)定义类的私有变量a、b,请在注释//********1********后添加适当的语句。(2)完
使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错,请改正其中的错误,使程序正确运行,并且使程序输出的结果为:HelloVisualC++!HelloVisualC++!!注意:错误的语句在//
使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,完成空出部分的程序。函数func(intA[NUM],intn)实现的功能是将数组的内容进行一次重新排序。排序的方法是:给定n,则下标为i的数字与下标为n.i的数字交换。
对长度为n的线性表进行顺序查找,在最坏情况下所需要的比较次数为()。
若有函数模板mySwap和一些变量定义如下:temp1ate<c1assT>voidmySwap(Tx,Ty);doubledl,d2;intil,i2;下列对mySwap的调用中,错误的是()。
对于语句cout<<endl<<x;中的各个组成部分,下列叙述中错误的是()。
下列关于运算符重载的叙述中,正确的是()。
若有函数模板mySwap和一些变量定义如下:()。template<classT>voidmySwap(Tx,Ty);doubled1,d2;inti1,i2;下列对mySwap的调用中,错误的是
有函数模板声明和一些变量定义如下:templateT1sum(T2,T3);doubledl,d2;则下列调用中,错误的是()。
随机试题
组成药物中含有黄连的方剂是
求由下列参数方程所确定的函数的二阶导数d2y/dx2:
犀黄丸具有的功用有
患者男性,55岁,咯血1天,量约600ml,色鲜红,体检:面色略苍白,心率100/min,血压13/10kPa(98/75mmHg),右肺闻及湿啰音,应首选的治疗是
传染病隐性感染是指
患者男性,25岁,系某大学的教师,平素不饮酒。在一次聚餐会时饮白酒三两后,瘫在地上,此症状最可能为
保障措施的实施期限一般不超过4年,可适当延长,但最长不超过8年(包括临时保障措施)。()
根据《票据法》的规定,汇票的()必须与付款人具有真实的委托付款关系,井且具有支付汇票余额的可靠资金来源。
根据个人所得税法律制度的规定,下列关于个人保险代理人和证券经纪人缴纳个人所得税的表述不正确的是()。
WhySustainableBuildingsNeedtoFocusonCommunityAndCollaboration?[A]Accordingtothegovernment,buildingsintheUKacco
最新回复
(
0
)