首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2020-07-23
47
问题
有如下程序:
#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全国计算机二级
相关试题推荐
若已经声明了函数"intfun(intx,inty=0);",则下列重载函数声明中,正确的是
下列关键字中,用来表示继承方式的是
设变量x和y为整型变量,若有函数调用为"fun(&x,&y)",则下列选项中,能够作为函数fun原型声明的是
下列代码段中声明了3个类:classPerson{};classStudent:publicPerson{};classUndergraduate:Student{};下列关于这些类之间关系的描述中,错误的是()。
若为类MyClass重载运算符"+",下列声明中,错误的是
下面不能作为结构化方法软件需求分析工具的是
设序列长度为n,在最坏情况下,时间复杂度为O(log2n)的算法是
某二叉树共有7个结点,其中叶子结点只有1个,则该二叉树的深度为(假设根结点在第1层)( )。
下列符号中,正确的C++标识符是()。
下列字符串中,不可以用做C++标识符的是()。
随机试题
如何确定电渣焊的焊接电压和送丝速度?
简述在国有独资公司中,必须由国家授权投资的机构或者国家授权的部门行使职权的几种情形。
下列物质在机体中异位后,不会刺激机体产生自身抗体的是
白前与前胡都具有的功效是()
A、加酸产生白色沉淀B、与硝酸银反应产生黑色沉淀C、麦芽酚反应D、硫色素反应E、呈色反应硫酸链霉素的鉴别反应为( )。
关于我国刑事诉讼中证明责任的分担,下列说法正确的是:
幼儿有的擅长绘画,有的善于动手制作,还有的很会讲故事。这体现的是幼儿()。
ThejournalScienceisaddinganextraroundofstatisticalcheckstoitspeer-reviewprocess,editor-in-chiefMarciaMcNuttann
Plantscanabsorbthecarbondioxidethroughtheir______duringthesunlighthoursandproduceoxygenwhichhumanbeingsneedt
TheWhiteHouseistheofficialresidenceofthePresidentoftheUnitedStates.Itwas【B1】______byJamesHoban,anIrishborn【
最新回复
(
0
)