首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Person{ public: Person(string
有如下程序: #include #include using namespace std; class Person{ public: Person(string
admin
2020-06-29
41
问题
有如下程序:
#include
#include
using namespace std;
class Person{
public:
Person(string n):name(n) { }
~Person() { cout<<’P’; }
private:
string name;
};
class Date{
public:
Date(int y=2012,int m=12,int d=21):year(y),month(m),day(d) { }
~Date() { cout<<’D’; }
private:
int year,month,day;
};
class Student:public Person{
public:
Student(string n,int y,int m,int d,char c)
:birthday(y,m,d),sex(c),Person(n) { }
~Student() { cout<<’S’; }
private:
Date birthday;
char sex;
};
int main(){
Student stu1("Zhang",1990,10,1,’F’);
return 0;
}
运行时的输出结果是
选项
A、S
B、SP
C、SPD
D、SDP
答案
D
解析
本题考查派生类的析构函数,派生类的析构函数执行顺序为先构造的后析构,后构造的先析构,所以执行Studentstu1("Zhang",1990,10,1,’F’);时,依次执行person、Date、Student构造函数,然后依次执行Student、Date、person的析构函数,所以输出为SDP,D选项正确。
转载请注明原文地址:https://www.kaotiyun.com/show/Ezyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#include#includeusingnamespacestd;classInstrument{public:Instrument
有如下类声明和函数声明classBase{intm;public:intn;protected:intp;};classDer
有如下类定义:classCup{public:voidSetPrice(doubleval=5.8);doubleGetPrice(){returnprice;
已知TV是一个类,并有函数func定义如下:voidfunc(){TVli,*net[2],company[3];}则在调用func()后,TV类的析构函数被调用的次数是
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程pmjl,该工程中包含程序文件main.cpp,其中有类Door(“门”)和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正
使用VC6打开考生文件夹下的源程序文件modil.cpp,该程序运行时有错误,请改正程序中的错误,使得程序输出:1,2,3,4,5,注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在********error
在下列选项中,不允许作为C++标识符的是
随机试题
组织文化的核心层是()
下列《长恨歌》诗句中,属于移情于景的是
髓袢利尿药:
按病因分类,外科疾病可分为________、________、________、________、________、________和________。
既能治风寒头痛,又能治疗鼻渊的药物是
具有下列哪一项条件的材料不能作为抗α、β辐射材料?[2006年第056题]
从18世纪到19世纪末,英国一直处于国际分工中心国家的地位,在资本主义世界对外贸中一直独占鳌头。()
简述评估的总结。
Whatisthepurposetoeatsomegarlicaccordingtothepassage?Itcan______.Whatisalsoagoodmethodtohelpyousleep
Ofallthe【C1】______ofagoodnight’ssleep,dreamsseemtobeleastwithinourcontrol.Indreams,awindowopensintoaworld
最新回复
(
0
)