首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Person{ public: Person(string
有如下程序: #include #include using namespace std; class Person{ public: Person(string
admin
2021-09-05
15
问题
有如下程序:
#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
解析
本题考查派生类的析构函数,派生类的析构函数执行顺序为先构造的后析构,后构造的先析构,所以执行Student stu1("Zhang",1990,10,1,’F’);时,依次执行person、Date 、Student构造函数,然后依次执行Student、Date 、person的析构函数,所以输出为SDP,D选项正确。
转载请注明原文地址:https://kaotiyun.com/show/nb5p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列语句中,与语句“1n=(a>b?(1)>c?1:0):0);”的功能等价的是()。
有如下程序;#include<iostream>usingnamespacestd;classBase{public:voidoutput(){cout<<1;}virtualvoid
下列选项可以做C++标识符的是()。
有如下程序:#include<iostream>usingnamespacestd;classA{public:A(){cout<<"A";}~A(){cout<<"~A";}};classB:publicA{A*p;pu
有如下程序:#includeusingnamespacestd;classMyClass{public:MyClass(intx):Val(x){}voidSet(i
下列关于指针的运算中,()是非法的。
一个栈的初始状态为空。现将元素1、2、3、4、5、A、B、C、D、E依次入栈,然后再依次出栈,则元素出栈的顺序是()。
在数据库系统中,用户所见的数据模式为()。
若MyTemp是一个只有一个虚拟类型参数的类模板,且有如下语句序列MyTemp<double>p2;MyTemp<long>p3[2];编译系统在处理上面的语句序列时,所生成的模板MyTemp的实例的个数是()。
下面不属于软件测试实施步骤的是
随机试题
试述谈判时提问的时机及要诀。
引起术后伤口裂开的原因有
工程施工质量不符合要求时,经返工重做或更换器具、设备的检验批应( )。
巴塞尔委员会正式发布的第三版巴塞尔协议(巴塞尔协议Ⅲ),确立了银行资本监管新标杆和新高度,使商业银行风险管理的模式发生了本质变化的时间为()
摩擦性失业主要是由()产生的。
头脑风暴法是由()首先提出。
在VisualFoxPro中,表的备注文件的扩展名是______。
ADULATION:
Navigationcomputers,nowsoldbymostcarmakers,cost$2000andup.Nosurprise,then,thattheyaremostoftenfoundinluxur
HollywoodForsakesHistoryforEventsA)OprahWinfreycallsBelovedtheblackequivalentofSchindler’sList.Tobesure,every
最新回复
(
0
)