首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Person{ public: Person(string
有如下程序: #include #include using namespace std; class Person{ public: Person(string
admin
2015-07-22
27
问题
有如下程序:
#include
#include
using namespace std;
class Person{
public:
Person(string n):name(n) { cout<<’P’; }
private:
string name;
};
class Date{
public:
Date(int y=2012,int m=12,int d=21):year(y),month(m),day(d) { 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) { cout<<’S’; }
private:
Date birthday;
char sex;
};
int main(){
Student stu1("Zhang",1990,10,1,’F’);
return 0;
}
运行时的输出结果是
选项
A、S
B、PS
C、DPS
D、PDS
答案
D
解析
本题考查派生类的构造函数,派生类的构造函数初始化时按照参数列表初始化顺序,所以先初始化Person(n),输出P,然后依次输出D和S,答案为D选项。
转载请注明原文地址:https://kaotiyun.com/show/yrNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下类定义:classMyClass{private:intid;chargender;char*phone;public:MyClass()
有以下类定义:classMyClass{public:MyClass(){cout<<1;}};则执行语句MyClassa,b[2],*p[2];后,程序的输出结果是______。
有以下程序:#include<iostream>inti=0;voidfun(){{staticihti=1;std::cout<<i++<<’,’;}std
关于面向对象的程序设计方法,下列说法正确的是______.
派生类的成员一般分为两部分,一部分是【】,另一部分是自己定义的新成员。
当输入“Thankyou”时下列程序的输出结果为()。#include<iostream.h>#include<iomanip.h>voidmain(){charli
有如下定义语句:inta[]={1,2,3,4,5};,则对语句int*p=a;正确的描述是()。
随机试题
甲股份有限公司因经营管理不善,无力偿还到期债务,该公司的债权人A公司于2012年6月12日向甲公司所在地法院提出破产申请。法院于6月15日通知甲公司,甲公司认为《企业破产法》不适用于股份有限公司,提出异议。法院于6月23日裁定受理该破产申请,同时指定B律师
Afreelyfallingbodyhasanaccelerationof32feetasecondduringeachsecond______itfalls.
酶能加速化学反应速度是属于哪一种效应
头孢噻吩的抗菌作用机制是
胃印戒细胞癌属于下列哪种组织学类型
平衡计分卡与传统业绩评价系统的区别体现在()。
人民警察的心理素质要求人民警察在特定职务活动中应当具备()。
我国《婚姻法》第11条规定:“因胁迫结婚的,受胁迫的一方可以向婚姻登记机关或人民法院请求撤销该婚姻。受胁迫的一方撤销婚姻的请求。应当自结婚登记之日起1年内提出。被非法限制人身自由的当事人请求撤销婚姻的,应当自恢复人身自由之日起1年内提出。”请问:
Onlyafterhehasacquiredconsiderablefacilityinspeaking______tolearntoreadandwrite.
Thiswillimprovetheirworkingconditionsandenablethemtodoublethe______.
最新回复
(
0
)