首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2021-05-06
24
问题
有如下程序:
#include
#include
using namespace std;
class Instrument{
public:
Instrument(string t="乐器",string n="无名"):type(t),name(n) { }
string GetType() const { return "乐器"; }
virtual 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、钢琴-无名
答案
A
解析
本题考查虚函数的运用,本题中基类Instrument,派生类Piano,其中虚函数为GetName,当定义Instrument *pi=new Piano("星空")时,调用派生类的GetType函数,得到type为乐器,name为星空,所以输出乐器-星空。选项A正确。
转载请注明原文地址:https://kaotiyun.com/show/pRfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
若已定义inta[]={0,1,2,3,4,5,6,7,8,9},*p=a,i;其中0≤i≤9,则对a数组元素不正确的引用是()。
若一个函数的原型为“int*Xfunl(intx,int&y,charz);”,则该函数的返回值类型为()。
有如下程序:#include#includeusingnamespacestd;intmain(){cout.fill(‘*’);cout
某类中有一个无参且无返回值的常成员函数Show,则正确的Show函数原型是()。
软件开发过程主要分为需求分析、设计、编码与测试4个阶段。其中,产生“软件需求规格说明书”的阶段是()。
下列关于运算符重载的叙述中,错误的是()。
下列符号中,正确的C++标识符是()。
假设函数fun已经定义,其原型为“voidfun(inta,intb=7,char*p=’’**’’);”下列函数调用中错误的是()。
结构化程序的三种基本控制结构是
随机试题
一台标注为“PentiumIII/600/128MB”的微型计算机,其中的“600”表示机器的()
函数f(x)=3x—x2的极值点是x=3。()
患者实感天旋地转,恶心欲吐,站立不稳,跌倒在地,神志清楚,数分钟后自行缓解。应诊断为()(2005年第70题)
机器单采浓缩白细胞悬液保存最佳温度为
A、宿主抗移植物反应B、急性排斥反应C、慢性排斥反应D、超急性排斥反应E、移植物抗宿主反应受者体液循环中若存在抗供者的抗体,常出现
某工程项目总价值1000万元,合同工期为18个月,现承包人因建设条件发生变化需增加额外工程费用50万元,则承包方提出工期索赔为()个月。
总分类账户与明细分类账户反映的经济内容相同,所提供会计信息的详略程度也相同。()
国际上对资产评估报告的分类一般包括()。
Therelationshipbetweenformaleducationandeconomicgrowthinpoorcountriesiswidelymisunderstoodbyeconomistsandpoliti
Someanimalbehavioristsarguethatcertainanimalscanrememberpastevents, anticipatefutureones,makeplansandcho
最新回复
(
0
)