首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class Publication{//出版物类 char name[30]; public: Publication(char*name=”未知名称”){ strcpy(this-
有如下程序: #include using namespace std; class Publication{//出版物类 char name[30]; public: Publication(char*name=”未知名称”){ strcpy(this-
admin
2017-10-17
43
问题
有如下程序:
#include
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
解析
因为getType是虚函数,所以p.getType( )执行继承类的getType函数,输出“书”;p.getName( )执行基类的getName-函数,输出“精彩人生”。总共输出“书:精彩人生”,故选D)。
转载请注明原文地址:https://www.kaotiyun.com/show/5XAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
C++语言中函数返回值的类型决定于
在关系模型中,二维表的行称为______。
若a是float型变量,且a=6,则表达式“a/2+(int)(a+1)%2”的值为【】。
下列程序的运行结果是#include<iostream.h>classA{inta;public:A(){a=0;}A(intaa){
软件生命周期包括八个阶段。为使各时期的任务更明确,又可以分为以下三个时期:软件定义期,软件开发期,软件维护期。编码和测试属于【 】期。
下列叙述中正确的是
有如下类的定义。那么空格处的语句是()。classMyClass{____________intx,y;public:MyClass(intx1=0,inty1=0){
友元运算符。obj1>obj2被C++编译器解释为()。
假定有下列变量定义: int k=7,x=12; 则能使值为0的表达式是
下列不属于软件工程三要素的是( )。
随机试题
下列何种药物的肝首过消除很强,生物利用度很低,故必须静注不能口服
猩红热的临床表现,下列哪项是错误的
患者,女,35岁,因剧烈腹痛来医院就诊。根据初步的判断,高度怀疑为霍乱,正在等待检查结果以确诊。该患者治疗无效不幸死亡,应将其尸体
建设工程项目管理规划的内容涉及的范围与深度要求是()。
下列关于期初余额的描述中,正确的有()。
()是指政府部门对公共部门或市场机制主体(单位)的补助支出。
2009年,某省国民经济企稳回升,民生状况不断改善,社会保持和谐稳定,农林牧渔业全面增长。农业增加值1883.4亿元,比上年增长2.7%;林业增加值71.3亿元,比上年增长9.8%;牧业增加值691.1亿元,比上年增长5.2%;渔业增加值459.8亿元,比
Judgingfromrecentsurveys,mostexpertsinsleepbehavioragreethatthereisvirtuallyanepidemicofsleepinessinthenatio
TheRivalsisa______satirizingthetraditionalpracticeoftheparentstoarrangemarriagesfortheirchildrenwithoutconside
A、Itdependsontheworkinghours.B、Itisabout500poundsaweek.C、ItwillbesetbytheHumanResources.D、Itistobenegot
最新回复
(
0
)