首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2019-07-10
21
问题
有如下程序:
#include
#include
using namespace std;
class Father{
public:
Father(string s):name(s) { }
~Father() { cout<<’F’; }
private:
string name;
};
class Mother{
public:
Mother(string s):name(s) { }
~Mother() { cout<<’M’; }
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) { }
~Child() { cout<<’C’; }
private:
string name;
int age;
};
int main(){
Child son("Zhang","Li","Ming",20);
return 0;
}
运行时的输出结果是
选项
A、C
B、CMF
C、CFM
D、20CMF
答案
C
解析
执行派生类构造函数的顺序是:
1、调用基类构造函数,2、调用子对象构造函数,3、再执行派生类析构函数,4、执行基类的析构函数。所以本题中执行析构函数为派生类的析构函数、Father的析构函数、Mother的析构函数,所以输出CFM,答案C正确。
转载请注明原文地址:https://kaotiyun.com/show/kP8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序:#include<iostream>usingnamespacestd;classsample{private:ihtn;public:
下列程序的输出结果是#include<iostream.h>voidmain(){char*str="12123434";intx1=0,x2=0,x3=0,x4=0,i;for(i=0;str[i]!=
在C++语言程序中
关于C++语言与C语言关系描述中错误的是
有如下的运算符重载函数定义:double operator+(int i,int k){return double(i+k);}但定义有错误,对这个错误最准确的描述是( )。
下列关于break语句的叙述不正确的是()。
在MyClass类的定义中,对赋值运算符:进行重载。请将画线处缺失的部分补充完整。【】MyClass::operator=(constMyClass&rhs){if(this==&rhs)return*this
下列选项,不正确的是
以下选项中,()是合法的用户标识符。
以下内容不属于算法程序所占的存储空间的是()。
随机试题
假设CPU执行某段程序时,950次从Cache得到数据,50次从主存得到数据,已知Cache存取周期为50ns,主存存取周期为200ns(设每次访问时,Cache访问与主存访问并发进行,如Cache命中则中断主存的访问)。求:Cache-主存系统的
A.cAMPB.cGMPC.单酰甘油D.二酰甘油能促进蛋白激酶C活性的第二信使是
女性,22岁,口服不详农药60ml后,呕吐,流涎,走路不稳,视物模糊,呼吸困难,口中有大蒜样气味。最重要的实验室检查是
某企业当月,固定资产原值200万元,累计折旧为60万元,固定资产减值准备40万元,则资产负债表中的“固定资产”项目是()。
国内某高校张教授2016年取得部分收入项目如下:(1)5月份出版了一本书稿,获得稿酬15000元,后因出版社添加印数,获得追加稿酬5000元。(2)9月份,教师节期间获得全国教学名师奖,获得教育部颁发的奖金50000元。(3)10月份取得5年期
WinRAR软件的作用有()。
2018年12月8日,“嫦娥四号”探测器在西昌卫星发射中心成功发射。下列关于“嫦娥四号”的说法不正确的是:
简述商业银行的主要资产业务。(东北财经大学2014真题)
Themoonwasobscuredbythickclouds.
Americansusemanyexpressionswiththeword"dog".PeopleintheUnitedStateslovetheirdogsandtreatthemwell.【B1】______H
最新回复
(
0
)