首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2021-05-06
45
问题
有如下程序:
#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/OUfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#inc1ude<iostream>usingnamespacestd;classBase{public:virtualvoidShow(){cout<<’B’;}};
数据库设计中,用E-R图来描述信息结构但不涉及信息在计算机中的表示,它属于数据库设计的()。
下列字符串中不能作为C++标识符使用的是()。
运算符重载是对已有的运算符赋予多重含义,因此()。
下列关于析构函数的描述中,错误的是()。
有如下类定义:classPoint{private;staticinthow_many;};_______how_many=0;要初始化point的静态成员how_many,下划线处应填
数据库DB、数据库系统DBS、数据库管理系统DBMS之间的关系是()。
以下选项中合法的实型常数是()。
对如下二叉树进行后序遍历的结果为()。
有如下语句序列:charstr[10];cin>>str;当从键盘输入"Ilovethisgame"时,str中的字符串是()。
随机试题
商法的概念和特征。(昆明理工大学2014年考研真题)
如果或有事项产生的经济利益基本确定能够流入企业时,企业就应将或有事项确认为资产。()
下列选项中,属于《证券发行与承销管理办法》规定的首次公开发行股票时禁止配售的对象有()。
课程建设和发展是国家的事情,和教师无关。()
【2015.福建】丰富的想象是打开知识宝库的金钥匙,这充分说明想象力的重要意义。简述教学过程中如何培养学生的想象力。
按照公文的行文关系来划分,中国人民大学和河南省人民政府之间的关系属于()。
使用VC6打开考生文件夹下的源程序文件modi2.cpp。请完成函数fun(inti),实现以下功能:当i等于5时,则打印如下内容。###############注意:不能修改程序的其他部分,只能修改fu
Canexercisebeabadthing?Suddendeathduringorsoonalterstrenuousexertiononthesquashcourtoronthearmytraininggr
在期权交易中,期权买方为获得相应权利,必须将()付给期权卖方。
Executivepaychecksmightgrabthemostheadlines,butit’stop-tiermedicalprofessionalswhoarebringinginthebiggestsalar
最新回复
(
0
)