首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2019-07-10
60
问题
有如下程序:
#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全国计算机二级
相关试题推荐
在重载运算符函数时,下面()。运算符必须重载为类成员函数形式。
下列有关抽象类和纯虚函数的叙述中,错误的是
一个在基类中说明的虚函数,它在该基类中没有定义,但要求任何派生类都必须定义自己的版本,此虚函数又称__________。
对于while、do…while循环结果说法正确的是______。
有如下程序:#includeusingnamespacestd;classTestClass{intn;public:TestClass(intk):n(k){}
派生类继承基类的方式有
源程序文档化要求程序应加注释。注释一般分为序言性注释和【】
设inta=10,b=ll,c=12;,表达式(a+b)〈c&&b==c的值是
软件需求规格说明书应具有完整性、无歧义性、正确性、可验证性、可修改性等特性,其中最重要的是【】。
软件开发环境是全面支持软件开发全过程的【】集合。
随机试题
冷哮证的面色是热哮证的面色是
()施工中使用的混凝土是各向同性材料。
在设计共箱封闭母线时,应装设伸缩节的是()。
以下关于预算定额的编制原则中不正确的是( )。
在执行中,双方当事人自行和解达成协议的。如果一方当事人不履行和解协议的,()。
计算机辅助工程网络计划编制的意义有()。
共产主义社会是人的自由而全面发展的社会,这里的“自由而全面发展”指的是()
EatingMeat—LessorMore?EverysecondintheUnitedStatesalone,morethan250animalsareslaughteredforfood,addingup
Formanycountriestherearetwolegalmeansforobtainingtechnology.topermitmultinationalcompaniestoconductbusinesswit
Smokingisconsidereddangeroustothehealth.Ourtobacco-seller,Mr.Johnson,therefore,alwaysaskshis【C1】______,iftheyar
最新回复
(
0
)