首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Father{ public: Father(string
有如下程序: #include #include using namespace std; class Father{ public: Father(string
admin
2019-07-10
39
问题
有如下程序:
#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全国计算机二级
相关试题推荐
在任何类中都有三种访问权限的数据成员,这三种权限是public、private和_______。
有如下程序:#include<iostream)usingnamespacestd;classBase{public:Base(intx=0){cout<<x;}};ClassDerived:
有如下程序:#include<iostream>usingnamespacestd;ClassA{public:A(){cout<<“A”;}~A(){cout<<“~A”;}};
在进行了任何C++流的操作后,都可以用C++流的有关成员函数检测流的状态,其中只能用于检测刚进行的操作是否失败函数名是
已知一个类A,类A有三个公有成员:voidf1(int),voidf2(int)和inta;定义指向类A成员函数的指针是()。
下面的______保留字不能作为函数的返回类型。
下列符号中可以用作C++标识符的是()。
有如下的运算符重载函数定义:double operator+(int i,int k){return double(i+k);}但定义有错误,对这个错误最准确的描述是( )。
设inta=10,b=ll,c=12;,表达式(a+b)〈c&&b==c的值是
C++中设置虚基类的目的是()。
随机试题
会计报表项目的金额,其直接来源是()。
空接事故发生后,地陪应首先()。
以下( )行为属于侵犯妇女的婚姻家庭权利。
构成公安赔偿的行为主体是公安机关及其人民警察,责任主体是公安机关。()
上个世纪中叶,法国著名社会学家布迪厄曾经十分犀利地指出,当代世界正面临着新自由主义市场化和全球化转向带来的严峻挑战,贫富分化不断加剧,怨恨歧视和社会排斥逐渐增加,社会整合力量日益消解,造成这些“世界的苦难”的主要原因就在于“国家的撤退”——国家以市场自由为
市场导向
IfyouwanttogetservedinanAmericanrestaurant,howcanyougetyourservice?
Becausethespeakerhadareputationforloquaciousness,thechairpersonwarnedhimtobesuccinct.
[A]school[B]numbers[C]emphasize[D]continue[E]significant[F]undoubtedly[G]weak[H]countries[I]invisible[J]ignore[K]unloc
Driverlesstrainsareatypeoftrainfirstdevelopedinthe1960s.Asthenameshows,thesetrainsoperateautomatically,with
最新回复
(
0
)