首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Person{ public: Person(string
有如下程序: #include #include using namespace std; class Person{ public: Person(string
admin
2020-05-14
11
问题
有如下程序:
#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://kaotiyun.com/show/Vu8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序#include<iostream>usingnamespacestd;classComplex{public:Complex(d
在C++中,编译时的多态性是通过模板或函数【12】实现的。
一棵二叉树共有47个结点,其中有23个度为2的结点。假设根结点在第1层,则该二叉树的深度为【1】。
表达式x.operator++()还可写成______。
【】允许用户为类定义一种模式,使得类中的某些数据成员及某些成员函数的返回值能取任意类型。
下列符号中可以用作C++标识符的是
数据库系统中实现各种数据管理功能的核心软件是______。
下列不属于软件工程3个要素的是( )。
C++语言标识符是以字母或______开头的,由字母,数字和下划线组成的字符串。
已知将运算符“+”和“*”作为类Complex的成员函数重载,设cl和c2是类Complex的对象,则表达式c1+c2*cl等价于()。
随机试题
资产评估强调确定评估基准日,这体现了资产评估的【】
A.常发生于骨皮质内,瘤巢周围有多量的致密反应性增生骨B.颅骨局限性、弥漫性密度增高及边缘清晰的成熟骨块与骨相连C.表现为长管状骨干骺端骨表面骨性隆起,可有蒂或无蒂D.常位于骨的中央,表现为蜀限、边缘清晰呈分叶状的膨胀性、椭圆形透明阴影E
在快速进行性肾小球肾炎病变发展过程中,关键性的病理改变是
患者,男孩,8岁,右上前牙肿块3天就诊。患儿半年来右侧经常冷热刺激痛,吃饭痛。偶有自发痛,一周前右上前牙疼痛加重,3天前牙床肿痛。进行诊断的重要依据是()
Nowmanypeoplearenotquiteinterestedintheirjobs.Someofthemwouldliketofindanewone.Butthe【E1】i______seemsto
古代印度被称为再生族的包括()。①婆罗门②刹帝利③吠舍④首陀罗
BurgerKingandKFChavelaunchedtheirfirstplant-basedburgers—butnotallvegansareonboard.AsBurgerKing’ssoy-basedRe
NET is both a business strategy from Microsoft and its(6)of(7)support for what are known as Web services, the ability to use the
Kolb’sLearningStylesPsychologistDavidKolbpresentedhistheoryoflearningstylesin1984.I.Afour-stagecycleoflea
SuggestopediaIntroduction-basis:how【T1】______worksandhowwelearnmosteffectively【T1】______-origin:【T2】____
最新回复
(
0
)