首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2020-07-23
8
问题
有如下程序:
#include
#include
using namespace std;
class Instrument{
public:
Instrument(string t="乐器",string n="无名"):type(t),name(n) { }
virtual 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,其中虚函数为GetType,当定义Instrument*pi=newPiano("星空")时,调用派生类的GetType函数,得到type为钢琴,name为星空,所以输出钢琴-星空。选项A正确。
转载请注明原文地址:https://kaotiyun.com/show/DFyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
必须用一对大括号括起来的程序段是()。
有如下程序:#includeusingnamespacestd;classTV{public:TV(ints=41):size(s){}
在一个有参函数的原型声明中可有可无的语法成分是
下面是重载为非成员函数的运算符的函数原型,其中错误的是()。
有如下类定义:classMyBase{intk;public:MyBase(intn=0):k(n){}intvalue()const{returnk;}};classMyDerived:MyBase{intj;
派生类的成员函数不能访问的基类的成员是
关于函数声明格式中的,下列叙述错误的是
下列有关继承和派生的叙述中,正确的是()。
运算符重载是对已有的运算符赋予多重含义,因此()。
下列关于return语句的叙述中,正确的是
随机试题
Pessimisticforecastssaythatthereisonlyenoughcoalfor450years,enoughnaturalgasfor50yearsandthatoilmightruno
有机磷酸酯农药抑制的酶是
对于承包商已完成的工作量的计量,必须经专业监理工程师检验,在工程质量达到( )才予以计量。
在施工质量管理中,以控制人的因素为基本出发点而建立的管理制度是()。
(2016年)2015年5月10日,甲公司向乙公司签发一张金额为50万元,出票后1个月付款的银行承兑汇票,经其开户银行P银行承兑后交付乙公司。5月15日,乙公司将该票据背书转让给丙公司。5月20日,丙公司将该票据背书转让给丁公司,并在票据上记载“不得转让”
过去人们都认为知识就是力量,大多数教师都传授具体知识。教师教、学生听,学生被动地接受知识。新的教育观念认为:学生必须掌握独立探索的方法.获得不断深造的能力,具有与集体合作的品质,与他人合作解决问题的社交能力,具备自如表达思想的能力等。这意味着()。
众所周知,西方法律的一个主要_________就是圣经,尤其是法律原则(法理),如自然法。哈佛大学的法律教授亚兰.德修威曾写了《法律的创世记:从(圣经)故事寻找法律的起源》,指出《圣经》所包含的许多高标准的道德观念,都纳进了西方法律,并一直________
什么是倾销?倾销的正常价格是怎样确定的?对非市场经济国家有什么不同?我国应如何应对?
当用户a刷新浏览器时,浏览器将会先卸载Applet,然后再【】。
将考生文件夹下ABCD文件夹设置为隐藏属性并取消存档属性。
最新回复
(
0
)