首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
54
问题
有如下程序:
#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全国计算机二级
相关试题推荐
有如下类定义classAnimal{public:virtualvoidName0=0;};classKoala:publicAnimal{public:voidName(){/*函数体略*/}};关于上述类定义,下列描述中错
有如下程序:#includeusingnamespacestd;classGA{public;virtualhatf(){retum1;}};classGB:pub
有函数模板声明和一些变量定义如下:templateT1sum(T2,T3);doubledl,d2;则下列调用中,错误的是()。
有如下程序:#include<iostream>usingnamespacestd;classMyClass{public:MyClass(){++count;}~MyClass(){--c
有如下程序:#includeusingnamespacestd;intmain(){charstr[100],*p;cout
有如下程序:#inc1ude<iostream>usingnamespacestd;c1assMyClass{public:MyClass(){cout<<’*’;}M
随机试题
A、Tworings.B、Agoldnecklace.C、Aringandtwogoldnecklaces.D、Tworingsandagoldnecklace.D
不易患龋的乳牙是
儿童期重要心理特点
红细胞的比容是指红细胞
医疗机构制剂申请要求临床研究受试例数不得少于()。
如果计算机字长是8位,那么用原码表示最大有符号定点整数的范围是()。
下列关于新奥法的说法,哪一选项是正确的?
根据《建设工程施工合同(示范文本)》(GF—99—0201)的规定,设备安装工程具备联动无负荷试车条件,发包人组织试车,并在试车前()小时以书面形式通知承包人。
某生产性企业2004年1月申报2003年度企业所得税,申报全年主营业务收入6500000元,其他业务收入320000元,全年实现会计利润98000元,并缴纳企业所得税26460元,2004年4月,主管税务机关对该企业所得税进行检查,查出部分经济业务及账务处
我国民法根据自然人不同的年龄和精神健康状况将自然人的民事行为能力分为()。
最新回复
(
0
)