首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序 #inc1ude<iostream> #inc1ude<iomanip> using namespace std; c1ass MyClass{ public: MyClass(){cout<<’
有如下程序 #inc1ude<iostream> #inc1ude<iomanip> using namespace std; c1ass MyClass{ public: MyClass(){cout<<’
admin
2017-06-18
51
问题
有如下程序
#inc1ude<iostream>
#inc1ude<iomanip>
using namespace std;
c1ass MyClass{
public:
MyClass(){cout<<’A’;)
MyClass(charc){cout<<c;}
~MyClass(){cout<<’B’;}
};
int main(){
MyClass p1,*p2;
p2 newMyClass(’X’);
delete p2;
retum 0;
}
执行这个程序屏幕上将显示输出( )。
选项
A、ABX
B、ABXB
C、AXB
D、AXBB
答案
D
解析
此题考查的是构造函数和析构函数。构造函数在对象被创建的时候由系统自动调用,而析构函数在对象的生存期即将结束的时候由系统自动调用。此题中,主程序在创建MayClass类的对象p1时,调用MayClass类的默认构造函数,输出字母A:然后在创建.p2对象时,调用带字母参数的构造函数,输出字母X;语句delete p2;调用析构函数,输出字母B:在主函数退出时,调用析构函数清除对象p1,输出字母B。
转载请注明原文地址:https://www.kaotiyun.com/show/imAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下函数模板声明: template<typename T> TMax(T a,T b){return(a>=b)?a:b;} 下列对函数模板Max()的调用中错误的是( )。
以下程序的执行结果是______。#include<iostream.h>classA{inta:public:voidseta(intx){a=x;}voidshowa(){cou
若类A和类B的定义如下:classA{inti,public:voidget();//...};classB:A//默认为私有派生{intk;public
下列关于虚函数的描述,错误的是( )。
下列函数原型声明中错误的是
关于类和对象描述错误的是
类classone在声明func成员函数时发生错误,出错原因是【 】。Classone{private:inta;
随机试题
三级管理结构有三个纵向层次,决策者划分销售部门,实行()。
护理濒死病人时,不正确的措施是
根据《建设工程工程量清单计价规范》GB50500—2013,下列资料中应作为企业投标报价依据的有()。
绘图仪是一种可以输出图形的硬拷贝设备,绘图仪可分为()。
86,82,90,(),106,42。
邓小平关于我国当前处于“社会主义初级阶段”的科学论断揭示了我国当前的()。
ThepassengersonthebuswatchedwithsympathyasSusanmadeherwaycarefullyupthesteps.Shepaidthedriverandthen,usin
人工智能
Intheinformationtechnologyindustry,itiswidelyacknowledgedthathowwellITdepartmentsofthefuturecanfulfilltheirb
TheFDAmayrescinditsapprovalofAvastin,acolon-cancerdrug.Ifthesummerof2009wastheseasonof"deathpanels,"as
最新回复
(
0
)