首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2021-07-02
17
问题
有如下程序:
#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
下列有关继承和派生的叙述中,正确的是()。
已知函数FA调用FB,若要把这两个函数定义在同一个文件中,则()。
下列描述中,不符合良好程序设计风格要求的是()。
C++系统预定了4个用于标准数据流的对象,下列选项中不属于此类对象的是()。
要建立文件流并打开当前目录下的文件file.dat用于输入,下列语句中错误的是()。
数据的存储结构是指()。
下列运算符函数中肯定不属于类FunNumber的成员函数的是()。
当使用ifstream流类定义一个流对象并打开一个磁盘文件时,文件的默认打开方式为()。
随机试题
我国在国家政权组织形式上采取()。
A.原发性高血压B.嗜铬细胞瘤C.原发性醛固酮增多症D.皮质醇增多症E.垂体腺瘤女性,42岁,间断性心悸,四肢冰冷,测血压达30/20kPa(220/150mmHg),尿VMA20mg/24h。最可能的诊断是
急性弥漫性增生性肾小球肾炎时,与肾小球滤过率降低不相关的病变是
患者,男,40岁,长期胸前憋闷,近日加重伴胸痛,痛有定处如刺,平素形体肥胖,常感头晕,肢体沉重,胃脘痞胀纳呆,痰多易咯,舌色暗红,苔腻,脉滑。该病应诊断为()
在进行建设项目财务评价时,利息备付率的基准判据是()。
资产、负债及所有者权益是经营成果的要素,收入、费用和利润是财务状况的要素。()
简述当代学前教育现代化水平提高的表现。
根据以下资料。回答96—100题。下列说法中错误的是()。
耐药性,是指病原体与药物多次接触后,对药物的敏感性下降甚至消失,致使药物疗效降低或无效,多用来指人。社会这个大肌体,同人一样,也会生出大大小小的疾病,如果在初犯的时候不能及时对症下药,彻底根治,也会产生耐药性,致使一些病症成为顽疾。下列哪一项最符合
下列关于信息系统建设中组织和领导的原则,正确的是()。
最新回复
(
0
)