首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2015-07-22
18
问题
有如下程序:
#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://jikaoti.com/ti/1dE0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下语句:inta[10]={0,1,2,3,4,5,6,7,8,9},*p=a;。下列对a数组元素的引用(其中0≤i<10)不正确的是()。
在表达式x-y中,“_”是作为非成员函数重载的运算符。若使用显式的函数调用代替直接使用运算符“_”,这个表达式还可表示为
有如下程序: #include<iostream> using namespace std; class Base { protected: in i; public
若某二叉树的前序遍历访问顺序是abdgcefh,中序遍历访问顺序是dgbaechf,则其后序遍历的结点访问顺序是
执行语句序列intx=10,&r=x;cout<<X<<’-’<<r<<endl;输出结果为【】。
数据结构分为逻辑结构和存储结构,循环队列属于工【 】结构。
有以下程序#include<iostream>usingnamespacestd;classsample{private:intx;public:sample(
下列叙述中正确的是
在结构化设计方法中生成的结构图(SC)中,带有箭头的连线表示
如果一个模板声明时有类型形参表,则多个参数之间必须使用______隔开,每个参数都必须重复使用关键字______。
随机试题
烧伤低血容量性休克常发生在伤后
头颈部肿瘤放疗中出现明显腮腺肿痛时正确的处理是
下列哪项不是有限责任公司章程中应当载明的事项?()。
按照企业所得税的规定,下列表述错误的是()。
()属于现代人力资源管理学的一般特点。
2012年7月北京遭遇61年来最大暴雨,直接经济损失多达百亿,这将导致2012年国内GDP下降百亿多。()
函数的无穷间断点的个数是()
数据库系统中实现各种数据管理功能的核心软件是______。
Afterthebirthofmysecondchild,Igotajobatarestaurant.Havingworkedwithanexperienced【C1】______forafewdays,Iwa
Asthenatureofinsiderdealingchanged,therewasacorrespondingneedto______otherlegalprinciplestofittheabuse.
最新回复
(
0
)