首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; class Publication{//出版物类 char name[30]; public: Publication(char*name="未知名称")
有如下程序: #include<iostream> using namespace std; class Publication{//出版物类 char name[30]; public: Publication(char*name="未知名称")
admin
2020-06-29
55
问题
有如下程序:
#include<iostream>
using namespace std;
class Publication{//出版物类
char name[30];
public:
Publication(char*name="未知名称"){
~strcpy(this->name,name):
}
const char*getName()const{return name;}
virtual const char*getType()const{return"未知类型";}
};
class Book:public Publication{//书类
public:
Book(char*name):Publication(name){}
virtual const char*getType()const{return"书";}
};
void showPublication(Publication&p){
cout<
}
int main(){
Book book("精彩人生");
showPublication(book);
return 0;
}
运行时的输出结果是( )。
选项
A、未知类型:未知名称
B、未知类型:精彩人生
C、书:未知名称
D、书:精彩人生
答案
D
解析
因为getl"ype是虚函数,所以p.getType()执行继承类的getType函数,输出“书”;p.getName()执行基类的getName函数,输出“精彩人生”。总共输出“书:精彩人生”,故选D。
转载请注明原文地址:https://kaotiyun.com/show/4zyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
结构化程序所要求的基本结构不包括( )。
下列有关类的表述中,正确的是
下列运算符中,不能被重载的是
结构化程序设计中,下面对goto语句使用描述正确的是
有如下类声明和函数声明classBase{intm;public:intn;protected:intp;};classDer
有下列类模板声明中,出现语法错误的是
使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,完成空出部分程序。函娄factor(int*des,int&length,intn)实现的功能是:将11所有基数存放到des中,通过length引用返回因数的个数,比如fa
有三个关系R、S和T如下:则由关系R和S得到关系T的操作是
下面不能作为软件设计工具的是
下列语句中错误的是
随机试题
板桩码头建筑物的优点是()等。
下列哪一种疾病与HLA-B27抗原相关性最明显
施工荷载不包括()。
票据的出票日期使用中文大写或小写均可。()
世界贸易组织的职能包括()。
Theymayhavelivedsome1,700yearsago,buttheancientMayahadanincredibleknowledgeofcelestialbodies,whichtheybelie
Morethan2,000yearsago,thephilosopherSocrateswanderedaroundAthensaskingquestions,anapproachtofind【M1】______truth
OneofNature’smostexcitingmysteriesishowpigeonsfindtheirwayhomeovervastdistances.NowGermanscientistsbelieveth
Someonetoldhimthathewouldgetpromotion,and_________________________(这是多年来他所期限望的).
Thetaskofbeingacceptedandenrolledinauniversitybeginsearlyforsomestudents,longbeforetheygraduatefromhighscho
最新回复
(
0
)