首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2020-07-23
63
问题
有如下程序:
#include
#include
using namespace std;
class Father{
public:
Father(string s):name(s) { }
~Father() { cout<<’F’; }
private:
string name;
};
class Mother{
public:
Mother(string s):name(s) { }
~Mother() { cout<<’M’; }
private:
string name;
};
class Child:public Mother,public Father{
public:
Child(string s1,string s2,string s3,int a):Father(s1),Mother(s2),name(s3),age(a) { }
~Child() { cout<<’C’; }
private:
string name;
int age;
};
int main(){
Child son("Zhang","Li","Ming",20);
return 0;
}
运行时的输出结果是
选项
A、C
B、CMF
C、CFM
D、20CMF
答案
C
解析
执行派生类构造函数的顺序是:
1、调用基类构造函数,2、调用子对象构造函数,3、再执行派生类析构函数,4、执行基类的析构函数。所以本题中执行析构函数为派生类的析构函数、Father的析构函数、Mother的析构函数,所以输出CFM,答案C正确。
转载请注明原文地址:https://kaotiyun.com/show/Dnyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列关于内联函数的叙述中,错误的是
下列情况中,不会调用复制构造函数的是
有如下类定义:classPoint{public:voidSetX(intxx);voidSetY(intyy);private:
Windows环境下,由C++源程序文件编译而成的目标文件的扩展名是
有如下类声明:classMau{intk;constintm;public:Mau(intk1,intm1);};则构造函数Mau的下列定义
下列叙述中正确的是
p是指向ClassA类型对象的指针。执行deletep;时,系统自动调用
深度为7的二叉树共有127个结点,则下列说法中错误的是
有函数模板声明和一些变量定义如下:templateT1sum(T2,T3);doubled1,d2;则下列调用中,错误的是
计算机软件包括
随机试题
加强党的执政能力建设的关键是()。
一组固有特性满足要求的程度称为()
职工赵某凭已审核的发票报销差旅费600元,同时退还原借款现金200元,该企业涉及的会计分录是()。
若预期市场利率下降,投资者应采取的措施为()。
下列对伊斯兰教禁忌表述正确的是()。
辛亥革命后建立的南京临时政府是一个资产阶级共和国性质的革命政权,这是因为
若是微分方程y′+p(x)=q(x)的两个解,求q(x).
Whenshopkeeperswanttolurecustomersintobuyingaparticularproduct,theytypicallyofferitatadiscount.Accordingtoa
下面不属于软件工程过程的4种基本活动()。
AnneSullivancouldnotteachHelenKellertospeakuntilsomeotherimportantthingshadbeenlearned.Thelittlegirlhadtol
最新回复
(
0
)