首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2021-05-06
33
问题
有如下程序:
#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/OUfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
对长度为n的线性表作快速排序,在最坏情况下,比较次数为()。
下列字符串中不能作为C++标识符使用的是()。
有如下类定义classAnimal{public:virtualvoidName0=0;};classKoala:publicAnimal{public:voidName(){/*函数体略*/}};关于上述类定义,下列描述中错
有如下程序:#inc1ude<iostream>usingnamespacestd;c1assMyClass{public:MyClass(){cout<<’*’;}M
下列关于析构函数的描述中,错误的是()。
有三个关系R、S和T如下:则由关系R和S得到关系T的操作是
下列关于输入流类成员函数getline()的叙述中,错误的是
下列关于运算符重载的描述中,错误的是
下列符号中可以用做C++标识符的是()。
在进行逻辑设计时,将E-R图中实体之间联系转换为关系数据库的
随机试题
熔化极氩弧焊可采用直流或交流电源。()
分离器排污时应平稳、缓慢进行,目的是()。
Studentswith_______problemsmayapplyforstudentloans.
目前,我国社区人口一般在()
CO2在血液中的运输形式,不包括()。
如下哪项血证,不宜用归脾汤治疗
下列关于资产的描述有误的是()。
证券发行人包括( )。
Nameshavegainedincreasingimportanceinthecompetitiveworldofhighereducation.Ascollegesstriveformarketshare,they
How’sthisforunintendedconsequences?Someofthebiggestbeneficiaries(受惠者)ofthewomen’smovementhavebeenmarriedmen.
最新回复
(
0
)