首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class Base1 { public: Base1(int d) { cout
有如下程序: #include using namespace std; class Base1 { public: Base1(int d) { cout
admin
2021-05-06
31
问题
有如下程序:
#include
using namespace std;
class Base1
{
public:
Base1(int d) { cout<
~Base1() { }
};
class Base2
{
public:
Base2(int d) { cout<
~Base2() { }
};
class Derived : public Base1,Base2
{
public:
Derived(int a,int b, int c, int d):Base1(b), Base2(a), b1(d), b2(c) { }
private:
int b1;
int b2;
};
int main()
{
Derived d(1,2,3,4);
return 0;
}
执行这个程序的输出结果是( )。
选项
A、1234
B、2134
C、12
D、21
答案
D
解析
本题考查派生类的构造函数和析构函数,在定义一个派生类的对象时,先调用基类的构造函数,然后再执行派生类的构造函数,对象释放时,先执行派生类的析构函数,再执行基类的析构函数。本题中定义一个派生类对象时,分别调用基类的构造函数,所以分别输出21。
转载请注明原文地址:https://kaotiyun.com/show/xHfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下语句序列:charstr[10];cin>>str;当从键盘输入“Ilovethisgame”时,str中的字符串是()。
有函数模板声明和一些变量定义如下:templateT1sum(T2,T3);doubledl,d2;则下列调用中,错误的是()。
有如下程序:#include<iostream>usingnamespacestd;classMyClass{public:MyClass(){++count;}~MyClass(){--c
有如下程序:#includeusingnamespacestd;intmain(){charstr[100],*p;cout
下列程序将x、y和z按从小到大的顺序排列,横线处应添加语句()。template<classT>voidfun(____){Ta;if(x>y){a=x;x=y;y=a;}if(y
随机试题
党的十九大明确指出,我国社会主要矛盾是()
外观检验不能发现的焊缝缺陷是()。
使用Mowry阿尔辛蓝过碘酸希夫(ABPAS)染色法进行黏多糖染色时,中性和酸性混合物质呈
胃蛋白酶原的激活物是
A.血清胆红素≥85μmol/LB.血清胆红素≤171μmol/LC.血清胆红素≤205μmol/LD.血清胆红素>256.5μmol/LE.血清胆红素>342μmol/L当发生胆红素脑病()。
燃气管道及其附件组装完成并试压合格后,应进行通球扫线,每次吹扫管道长度不宜超过()km。
如果A、B两只股票的收益率变化方向和变化幅度完全相同,则由其组成的投资组合()。
Inordertosurvive,tofeed,clotheandshelterhimselfandhischildren,manisengagedinaconstantstrugglewithnature.
我国历史上第一部社会主义类型的宪法是()。
A.sothatB.preferenceC.normalD.circleE.callsforF.problemG.longerH.cycleI.matterJ.illustratesK.hand
最新回复
(
0
)