首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class Base { int x; public: Base(int n=0): x(n) { cout
有如下程序: #include using namespace std; class Base { int x; public: Base(int n=0): x(n) { cout
admin
2020-06-29
16
问题
有如下程序:
#include
using namespace std;
class Base {
int x;
public:
Base(int n=0): x(n) { cout<
int getX()const { return x; }
};
class Derived: public Base {
int y;
public:
Derived(int m, int n): y(m), Base(n) { cout<
Derived(int m): y(m) { cout<
};
int main()
{
Derived d1(3), d2(5,7);
return 0;
}
执行这个程序的输出结果是( )。
选项
A、375
B、357
C、0375
D、0357
答案
C
解析
本题考查派生类的构造函数和析构函数,在定义一个派生类的对象时,先调用基类的构造函数,然后再执行派生类的构造函数,对象释放时,先执行派生类的析构函数,再执行基类的析构函数。本题中定义了一个对象d1,先执行基类的构造函数输出0,再执行派生类的构造函数输出3,然后定义了一个对象d2(5,7),其中需要调用基类的构造函数输出7,最后输出5,所以答案为C。
转载请注明原文地址:https://jikaoti.com/ti/Qrl0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
使用VC6打开考生文件夹下的源程序文件modil.cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为:i=5i=10i=15i=20注意:错误的∥********error********语句在的下
使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示雇员的Employee类,但类Employee的定义并不完整。请按要求完成下列操作,将类CEmployee的定义补充完成。(1)定义私有数据成员name、street、city、
使用VC6打开考生文件夹下的源程序文件modil.cpp。本程序要求输入一字符串,然后将其中的小写字母改变成大写字母,字符可能输入多行,当输入字符“?”时,默认字符输入结束,最后把结果输出到界面。注意:不要改动main函数,不能增行或删行,也不能
使用VC6打开考生文件夹下的源程序文件modil.cpp,该程序运行时有错,请改正其中的错误,使程序正常运行,即使程序在界面输出以下类似内容:0012FF6810012FF3C50012FF6C20012FF444
使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和C代码,完成空出部分的程序,实现函数fun(char*s1,char*s2)将字符串s2连接在字符串s1之后,构成一个首指针为s1的字符串。注意:不能修改函数的其他部分。#in
下列函数声明中,错误的是
下列关于函数的叙述中,正确的是
在定义一个类模板时,模板形参表是用一对括号括起来的,所采用的括号是
已知枚举类型声明语句为:enumCOLOR{WHITE,YELLOW,GREEN=8,RED,BLACK=15};则枚举常量RED的值为
语句int*p=&k;定义了指针p,与这个语句等效的语句序列是()。
随机试题
患者,男,51岁,因“鼻塞伴头痛半年”就诊,鼻咽镜检查发现右侧鼻咽部黏膜隆起明显,行活检明确为鼻咽腺样囊性癌,下面说法正确的是
代谢性酸中毒的发病机制是
解除有机磷中毒时毒蕈碱中毒性作用,首选
设甲、乙、丙、丁四国就流经四国的多国河流的航行事项于2007年缔结条约,规定缔约国船舶可以在四国境内的该河流中通航。2012年,甲国新当选的政府宣布:因乙国政府未能按照条约的规定按时维修其境内航道标志,所以甲国不再受上述条约的拘束,外国船舶进入甲国境内的该
[2018年真题]对中、高频均有吸声效果,且安拆便捷,兼具装饰效果的吸声结构应为()。
证券投资基金的特点有()。
国务院旅游主管部门和县级以上地方人民政府应当根据需要建立旅游公共信息和咨询平台,()向旅游者提供旅游景区、线路、交通等必要信息和咨询服务。
请阅读以下对话,回答问题。领导:“为了提升居民幸福感,咱们所已经在辖区内开展了为期一个月的打击入室盗窃的专项整治行动,针对这次行动,你做一个总结报告吧,为以后的打击犯罪行动积累经验,为群众提供更多帮助。”小刘:“好的,具体要求是什么?多
2012年9月30日~10月7日中秋、国庆黄金周期间,全国纳入监测的119个直报景区点共接待游客3424.56万人次,同比增长20.96%;旅游收入17.65亿元,同比增长24.96%。9月29日至10月6日,民航全国累计发送55926班次,运送旅客人数7
我国政治体制改革的基本原则包括()
最新回复
(
0
)