首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2015-07-22
39
问题
有如下程序:
#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/MkNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序: #qnclude<iostream> #include<iomanip> using namespace std; class CSum { int x,y;
设inta=l,b=2;,则(a++)+b和a+++b这两个表达式的值分别为
下列关于this指针的叙述中,正确的是
数据库系统的核心是
下列叙述中正确的是
已知:doubleA(doubleA){return++a;}和intA(intA){return++a;}是一个函数模板的两个实例,则该函数模板定义为【】
有如下程序:#include<iostream>usingnamespacestd;classAA{public:virtualvoidf(){
下列程序中画线处应填入的语句是classBase{public:voidfun(){cout<<"Baseoffun"<<end1;}};
利用成员函数对双目运算符重载,其左操作数为______,右操作数为______。
下列符号中能够作为C++标识符的是
随机试题
不属于555定时器构成的单稳态触发器的典型应用为()。
组织变革按照()可以分为以组织为重点的变革和以人为重点的变革和以技术为重点的变革。
下列哪项引起回心血量减少
健康危险度是指外源化学物
王莫婵在本案中处于什么法律地位?()。如果海淀区法院对此案作出判决后,王莫婵才知自己的权利被侵犯,下列表述中哪些是正确的?()。
债务期限配比的正确做法是()。
执行价格是指期权的买卖双方敲定的期货期权合约的价格。()
某市某公安分局某派出所干警周某在执行巡逻任务时,非法殴打他人致残。如果该受害人请求赔偿,赔偿义务机关是()。
WhenIwasalittlegirl,everytimemydadwasrepairingsomething,he【K1】______askmetoholdthehammer,andmeanwhile,have
There(are)notmanypeopleinthiscity(which)(own)thehousesthey(livein).
最新回复
(
0
)