首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
2021-06-10
28
问题
有如下程序:
#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://kaotiyun.com/show/y0fp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序段:inti=4;intj=1;intmain(){inti=8,j=i;eout<<i<<j<<end1;}运行时的输出结果是()。
若有下面的函数调用:fun(a+b,3,max(n-1,b))则fun的实参个数是()。
派生类的对象对它的基类成员中()是可以访问的。
有如下程序:#includeusingnamespacestd;classB{public:B(intxx):x(xx){++count;x+=10;}virtualvoids
下列符号中能够作为C++标识符的是()。
下列方法中,属于白盒法设计测试用例的方法的是()。
在面向对象方法中,不属于“对象”基本特点的是()。
执行下列语句段后,输出字符“*”的个数是()。for(inti=50;i>1;I-=2)cout
数据库系统的核心是()。
数据库系统的三级模式不包括()。
随机试题
权益法主要适用于投资企业对被投资企业具有()的长期股权投资。
艾滋病/HIV感染的治疗方法有
柔痉的治疗选方为
收入能够导致企业所有者权益增加,但导致所有者权益增加的不一定都是收入。()
有以下程序:#includevoidfun(int*s){staticintj=0;dos[j]+=s[j+1];while(++j
为考生文件夹下SCREEN文件夹中的PENCEL.BAT文件建立名为BAT的快捷方式,存放在考生文件夹下。
Toitsfans,itisaddictive.Tothemedia,itisapromisingmoney-maker.Sudoku,anoldpuzzlelongpopularinJapanisfastg
A.accreditedjournalist0B.attributionC.columnistD.continuedstoryE.contributingeditorF.pressconferenceG.correspon
A、Wecanfindquiteafewwaystoavoidstress.B、Stressisalwaysharmfultopeople’shealth.C、It’seasytochangethehabito
A、Sheofferedtohelptheman.B、Sheborrowedthebooksfromtheman.C、Shebroughtthebooksthemanaskedfor.D、Sheletthem
最新回复
(
0
)