首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2015-07-22
64
问题
有如下程序:
#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/5uNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
以下程序的输出结果是【】。#include<iostream.h>classobject{private:intval;public:
类模板的模板参数()。
类模板template<classT>classx(…),其中,友元函数f成为从该类模板实例化的每个模板类的友元,则其说明应为()。
下列程序在构造函数和析构函数中申请和释放类的数据成员int*a,申请时使用形参b初始化a,请填空。classA{public:A(intb);~A();private:
对于下面定义的类MyClass,请在函数f()中添加对象成员把n的值修改为50。classMyClass{public:MyClass(intx){n=x;}voidSetNum(i
下面程序的结果是#include<iostream.h>classA{public:A(){cout<<"construtA"<<endl;}virtual~A(){cout<<
数据库系统的核心是
在面向对象方法中,类之间共享属性和操作的机制称为【】。
源程序中应包含一些内部文档,以帮助阅读和理解源程序,源程序的内部文档通常包括选择合适的标识符、注解和()。
随机试题
可用于治疗便秘的食饵有
正常人每100ml血浆中钙,磷浓度乘积是
医师李某,申请开办儿科诊所,经执业注册后,开展了儿科诊疗活动,同时也以所学知识诊治一些妇科病人,李某的行为是
A.黄连B.黄芩C.黄柏D.苦参E.栀子
适用于400m3以上的球罐组装,目前国内应用最广、技术最成熟的球罐组装方法是()。
在美国,商标的首先使用人得到商标所有权,即使没办理注册手续,法律也给予承认和保护。()
力源公司2014年12月31日应收票据的账面余额为200万元,已提坏账准备30万元,应付票据的账面余额为70万元,其他应收款的账面余额为30万元。该企业2014年12月31日资产负债表中应收票据项目的金额为()万元。
Long-marriedcouplesoftenscheduleaweekly"datenight"—aregulareveningoutwithfriendsoratafavoriterestauranttostre
A、ShethinksMienisathief.B、ShethinksAllenisclever.C、ShethinksAllentookherearringsbymistake.D、ShethinksAllen
Forthispart,youareallowed30minutestowriteacompositiononthetopicAWelcomeSpeech.Youshouldwriteatleast120wo
最新回复
(
0
)