首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2021-07-02
29
问题
有如下程序:
#include
#include
using namespace std;
class Father{
public:
Father(string s):name(s) { cout<<’F’; }
~Father() { }
private:
string name;
};
class Mother{
public:
Mother(string s):name(s) { cout<<’M’; }
~Mother() { }
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) { cout<<’C’; }
~Child() { }
private:
string name;
int age;
};
int main(){
Child son("Zhang","Li","Ming",20);
return 0;
}
运行时的输出结果是
选项
A、C
B、FMC
C、MFC
D、FMC20
答案
C
解析
执行派生类构造函数的顺序是:1、调用基类构造函数,2、调用子对象构造函数,3、再执行派生类析构函数,4、执行基类的析构函数。所以本题中执行构造函数为先执行基类Mother的构造函数、然后执行基类Father的构造函数,再执行派生类的构造函数函数,所以输出MFC,答案C正确。
转载请注明原文地址:https://kaotiyun.com/show/RYfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下类定义和变量定义:classParents{public:intpublicData;private:intprivateData;};classChildA:publ
有如下类定义:classMyBase{intk;public:MyBase(intn=0):k(n){}intvalue()const{returnk;}};classMyDerived:MyBase{intj;public
设有如下关系表:则下列操作中正确的是()。
在下列原型所示的C++函数中,按“传值”方式传递参数的是()。
将运算符重载为类成员函数时,其参数表中没有参数,说明该运算符是()。
有如下程序:#inc1ude<iostream>usingnamespacestd;c1assBase{private:voidfunl()const{cout<<"funl";}
下列关于运算符重载的叙述中,正确的是()。
结构化程序所要求的基本结构不包括()。
支持子程序调用的数据结构是
使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错误,请改正程序中的错误,使得程序输出:1,2,3,4,5,注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//**
随机试题
消火栓箱按消防水带安置方式不同,可分为挂置式、卷盘式、卷置式和托架式。()
传统的技术引进格局是()
血压升高是下列哪种疾病的危险因素
下列情况属于不合理配伍是
一家基金公司通过一家证券公司的交易席位买卖证券的年交易佣金,不得超过其当年所有基金买卖证券交易佣金的50%。()
散客旅游团队具有哪些明显的特点?
Whatisyourfavoritecolor?Doyoulikeyellow,orangeorred?Ifyoudo,youmustbeanoptimist,aleader,anactivepemonwhoenjo
“现实生活中,喜欢抱怨的人一般能力比较差”.你怎么理解这句话?
Consequently,mostoftheworld’sfridgesaretobefound,notinthetropicswheretheymightproveuseful,butinthewealthy
设有表示学生选课的三张表,学生S(学号,姓名,性别,年龄,身份证号),课程C(课号,课名),选课SC(学号,课号,成绩),则表SC的关键字(键或码)为
最新回复
(
0
)