首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class test{ private: int a: public: test0{cout+”constructor”+en
有如下程序: #include using namespace std; class test{ private: int a: public: test0{cout+”constructor”+en
admin
2019-04-01
22
问题
有如下程序:
#include
using namespace std;
class test{
private:
int a:
public:
test0{cout+”constructor”+endl;}
test(int a){cout+a+endl;)
test(const test&test)
{
a=test.a:
cout+“copy constructor”+endl;
)
test(){Cout+”destructor”+endl;)
);
int main()
{
test A(3);
return 0:
}
运行时输出的结果是( )。
选项
A、3
B、constructor
destructor
C、copy constructor
destructor
D、3
destructor
答案
D
解析
此题考查的是构造函数和析构函数。一个类可以有多个构造函数,但只能有一个析构函数。每一个对象在被创建时,都会隐含调用众多构造函数中的一个,而在销毁时又会隐含调用唯一的析构函数。此题中,主函数创建对象A是会隐含调用test(int a)这个构造函数,输出3:接着主函数结束,对象A销毁又隐含调用~test()析构函数输出destructor。
转载请注明原文地址:https://kaotiyun.com/show/peAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在E-R图中,用来表示实体的图形是()。
对表达式for(表达式1;;表达式3)可理解为
有以下语句,则对a数组元素的引用不正确的是(0≤i≤9)inta[10]={0,1,2,3,4,5,6,7,8,9},*p=a;
执行语句for(i=1;i++<4;);后,变量i的值是
当使用fstream流类定义一个流对象并打开一个磁盘文件时,文件的隐含打开方式为
下面关于数组的初始化正确的是
下列是关于派生类声明的开始部分,其中正确的是
E-R图中用矩形表示实体(等同于表),用椭圆形表示实体的属性(等同于表中的字段),用菱形表示实体关系(等同于外键)。
1______是实现C++语言编译时多态性的机制,2______是实现C++语言运行时多态性的机制。2______。
C++中多态性分为编译时的多态性和运行时的多态性,其中运行时的多态性时通过__________实现的。
随机试题
A.主要作用于α受体B.主要作用于β受体C.主要作用于β1受体D.对α和β受体作用都强E.对α和B受体作用都弱肾上腺素()。
4-甲基伞酮用360nm激发光照射,发出什么范围的荧光
儿童第二次生长突增的高峰是在
适宜用清热解毒,软坚散结法治疗的流行性腮腺炎的证候是
根据《建筑地基基础设计规范》(GB50007—2002),确定地基承载力特征值理论公式是()。
风险管理的过程主要包括()以及沟通和记录等。
下列项目中属于土地增值税的纳税人转让房地产取得应税收入的是()。
设A(x1,y1),t),B(x2,y2),C(x3,y3)为平面上不共线的三点,则三角形ABC的面积为()。
()的标志是守恒观念的形成。
下列不属于第一顺序法定继承人的是()。
最新回复
(
0
)