首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2015-07-22
59
问题
有如下程序:
#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://www.kaotiyun.com/show/MkNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列各函数的说明中,表示纯虚函数的是()。
假定MyClas为一个类,则该类的拷贝构造函数的声明语句为()。
在下面程序的横线处填上适当的内容,使程序执行后的输出结果为ABCD。#include<iostream>usingnamespacestd;classA{public:A(){cout<<’A’;}
下列不是描述类的成员函数的是
下面程序的运行结果为#include<iostream.h>classA{staticintn;public:A(){n=1;}A(intnum){n=
若某二叉树的前序遍历访问顺序是abdgcefh,中序遍历访问顺序是dgbaechf,则其后序遍历的结点访问顺序是
在进行任何C++流的操作后,都可以用C++流的有关成员函数检测流的状态;其中只能用于检测输入流状态的操作函数名称是
下列叙述中正确的是
C++语言中关键字运算符有new,delete和【】。
随机试题
符合高能磷酸键的叙述是
滤过分数是指
宜在清晨服用的药物有()。
下列表述中错误的是()。
本地杂草野花由于经历了千百年的自然?_______,对当地气候和土质都有极好的适应性,根本不需要过多额外的养护。而且,与属于外来物种的人工草坪相比,本地杂草野花还有一个_______就是生态安全。依次填入画横线部分最恰当的一项是:
利用虚拟技术进行设备管理的主要目的是()。
おなかの________が悪いので、ごはんは食べられない。
Theword"threatened"inthefirstsentenceofthefirstparagraphcouldbebestreplacedbyThefirstword"He"inparagraph6
HitlerwantedtoinvadeEngland【56】couldnotdosountiltheRAFwasdestroyed.InAugust1940theGermansbegandaylightbombin
Bigdatacanbedefinedasinformationthatistoobigorcomplextobecontainedorprocessedbyanyonemachineorperson.
最新回复
(
0
)