首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2021-09-05
55
问题
有如下程序:
#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://www.kaotiyun.com/show/Pz5p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列控制格式输入/输出的操作符中,能够设置浮点数精度的是()。
有如下程序:#includeusingnamespacestd;classPoint{public:staticintnumber;public:Point(){number++;}~Point(){number一一;}};
将E—R图转换为关系模式时,实体和联系都可以表示为()。
以下程序的执行结果是()。#include<iostream.h>classTcstClass2{public:TestClass2(){};TestClass2(inti,intj
有如下类定义:classSample{public;Sample(intx):ref(x){}∥①private:Sample():ref(0){}∥②staticint
已知在一个类体中包含如下函数原型:VOLUMEoperator.(VOLUME)const;,下列关于这个函数的叙述中,错误的是()。
下列叙述中正确的是()。
下列字符串中,正确的C++标识符是()。
数据库系统在其内部具有3级模式,用来描述数据库中全体数据的全局逻辑结构和特性的是()。
算法的空间复杂度是指()。
随机试题
A=JohnGrayB=AyaanHirsiC=QinglianHeD=MichaelWalzerWhichauthor(s)believe(s)thatthefreemarket
A.精神分裂症B.脑器质性精神病C.症状性精神病D.情感性精神病E.神经症下列症状最常见于上述哪种疾病鲜明生动的幻视
病人,男性,患肾炎已3年。近日发现尿少,晨起眼睑肿胀,内生肌酐清除率为45ml/min。内生肌酐清除率实验结果提示
防腐衬胶管道未衬里前应先预安装,预安装完成后,需要进行()。
存在( )的情况,责任人终身不得重新取得会计从业资格证书。
因国际货物买卖合同或者技术进口合同发生争议,其诉讼时效为()年。
学校侵犯了教师的合法权益,受理教师申诉的机关是()
为了检验某含有NaHCO3杂质的Na2CO3样品的纯度,现将w1克样品加热,其质量变为w2克,则该样品的纯度(质量分数)是()。
Fordecades,postersdepictingrabbitswithinflamed,reddenedeyessymbolizedcampaignsagainstthetestingofcosmeticsonani
RetirementforMarionMarionWhiteisduetoretirenextweekfromwell-knownlocallawfirmBarney&Francis,(29)...
最新回复
(
0
)