首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Person{ public: Person(string
有如下程序: #include #include using namespace std; class Person{ public: Person(string
admin
2015-07-22
51
问题
有如下程序:
#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://www.kaotiyun.com/show/yrNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
当数据的物理结构(存储结构、存取方式等)改变时,不影响数据库的逻辑结构,从而不致引起应用程序的变化,这是指数据的【】。
有以下程序:#include<iostream>usingnamespacestd;classComplex{public:Complex(doubler=0,doublei=0)
有以下类定义:classMyClass{private:intid;chargender;char*phone;public:MyClass()
一个类可以同时继承多个类,称为多继承。下列关于多继承和虚基类的表述中,错误的是______。
有以下程序#include<iostream>usingnamespacestd;classMyClass{public:MyClass(intn){number=n;}
以下哪个基类中的成员函数表示纯虚函数()。
随机试题
猪巨吻棘头虫的感染期
某区人民医院计划建设门诊大楼,遂向市建设局申请施工许可。市建设局经过审查,作出准予施工许可。在该大楼施工过程中,市政府发现该人民医院尚未办理该大楼用地的批准手续,欲撤销市建设局的施工许可,对此下列哪些说法是不正确的?
甲公司和乙公司双方签订买卖合同,甲公司向乙公司购入价值100万元的货物用于试制新产品,承诺3个月后付款。甲公司应乙公司的要求,请A公司和B公司做担保人。其中,A公司以自有的一套加工设备提供抵押担保,B公司提供保证担保。乙公司向甲公司按期供货后,甲公司为筹集
票据贴现的贴现期限最长不得超过()。
中国共产党的根本宗旨和一切工作的根本出发点是()。
投资回收期
“熙宁兴学”之后,宋代太学中曾经普遍实施的一种将学生平时品行、学业表现与考试成绩结合考察的教学评价和管理制度,称为()
数据库管理系统常见的数据模型有层次模型、网状模型和______3种。
TheUnitedNationLawoftheSeaConferencewouldsoonproduceanocean-miningtreatyfollowingits____declarationin1970that
Adviceto"sleeponit"couldbewellfounded,scientistssay.Afteragoodnight’ssleep,aproblemthatseemedinsurmountable(
最新回复
(
0
)