首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2019-07-10
63
问题
有如下程序:
#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全国计算机二级
相关试题推荐
执行语句:cout<<setfill(’*’)<<setw(10)<<setfill(’#’)<<left<<123<<"OK"<<endl;后将输出
有如下程序:#include<iostream>usingnamespacestd;intfun1(intx){return++x;}intfun2(int&x){return++x;}intmai
下列有关抽象类和纯虚函数的叙述中,错误的是
关于虚函数,以下说法正确的是()。
对于while、do…while循环结果说法正确的是______。
有如下程序:#include<iostream)usingnamespacestd;classBase{public:Base(intx=0){cout<<x;}};ClassDerived:
以下选项中,合法的字符常量是()。
下列关于类与对象的说法中,不正确的是()。
下列选项中,不是C++关键字的是()。A)classB)functionC)friendD)virtual
下列选项中不符合良好程序设计风格的是()。
随机试题
退行性核左移提示
在进行网络计划费用优化时,应首先将( )作为压缩持续时间的对象。
以欺骗、贿赂等不正当手段取得注册证书的,由注册机关()。
下列支出中,属于资本性支出的有()。
下列关于资源税课税数量的表述中,错误的有()。
根据《评价指引》的要求,下列属于内部控制评价应遵循的原则的有()。
一般来说,仓储用房的经济寿命是()年。
Inprojectmanagement,a_______isalistingofaproject’smilestones,activities,anddeliverables,usuallywithintendedstart
必须用一对大括号括起来的程序段是()。
TheValueofWritingWell[A]It’sthattimeofyearagain.No,not"theholidayseason".Imean,itisholidaytime,butfor
最新回复
(
0
)