首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2021-05-06
85
问题
有如下程序:
#include
#include
using namespace std;
class Instrument{
public:
Instrument(string t="乐器",string n="无名"):type(t),name(n) { }
virtual string GetType() const { return "乐器"; }
string GetName() const { return "无名"; }
protected:
string type,name;
};
class Piano:public Instrument{
public:
Piano(string n,string t="钢琴"):Instrument(t,n) { }
string GetType() const { return "钢琴"; }
string GetName() const { return name; }
};
int main(){
Instrument *pi=new Piano("星空");
cout<
GetType()<<’-’<
GetName();
delete pi;
return 0;
}
运行时的输出结果是
选项
A、乐器-星空
B、乐器-无名
C、钢琴-星空
D、钢琴-无名
答案
D
解析
本题考查虚函数的运用,本题中基类Instrument,派生类Piano,其中虚函数为GetType,当定义Instrument *pi=new Piano("星空")时,调用派生类的GetType函数,得到type为钢琴,执行GetName时只能执行基类的这个函数,输出无名,所以输出钢琴-无名。选项D正确。
转载请注明原文地址:https://kaotiyun.com/show/HFfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
已知函数f的原型是“voidfont*x,int&y);”,变量v1、v2的定义是“intv1,v2;”,下列调用语句中,正确的是()。
有如下程序:#inc1ude<iostream>usingnamespacestd;c1assBase{public:virtualvoidShow(){cout<<’B’;}};
下列有关类成员的叙述中,正确的是()。
下列关于this指针的叙述中,正确的是()。
下面程序的输出结果为()。#include<iostream.h>voidmain(){intx;int&y=x;//变量引用y=99;cout<<"x="<<x<<endl;}
下列关于运算符重载的叙述中,错误的是()。
有如下函数模板定义:templateT1Fun(T2n){returnn*5.0;}若要求以int型数据9作为函数实参调用该模板,并返回一个double型数据,则该调用应表示为()。
有三个关系R、S和T如下:则由关系R和S得到关系T的操作是
算法的空间复杂度是指()。
对于循环队列,下列叙述中正确的是()。
随机试题
Thefollowingchartshowsthechannelsthroughwhichuniversitygraduatesgettheirfirstjoboffers.Lookatthechartcarefull
代谢性酸中毒患者特征性的临床表现是
慢性髋关节感染表现
以下属于竣工结算编制依据的是()。
风管系统安装时,法兰垫料应采用不产尘和不易老化的()。
某项目属于按规定应当进行消防设计的建筑工程,下列关于建筑工程消防设计、验收的表述中正确的是( )。
运用PDCA管理法来控制和提高饭店的质量是一个()的过程。
安土城、大阪城和()为日本三个古城堡。
下面列出的数据模型中,哪一种是数据库系统中最早出现的数据模型?
YouwillhearpartofaradiointerviewwithPaulJefferson,whosetuphisownimportbusiness.Foreachquestion(23-30),m
最新回复
(
0
)