首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2015-07-22
51
问题
有如下程序:
#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/VgNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在结构化设计方法中,生成的结构图(SC)中,带有箭头的连线表示
有以下程序:#include<iostream>usingnamespacestd;classCSample{private:inti;public:CSample(
只能作为成员函数重载的是
下列关于C++函数的描述中正确的是
C++语言的参数传递机制包括传值和传地址两种,如果调用函数时,需要改变实参或者返回多个值,应该采取【】方式。
下面的叙述中,不符合赋值兼容规则的是()。
下列叙述中正确的是
数据管理技术的发展是与计算机技术及其应用的发展联系在一起的,经历了由低级到高级的发展过程。分布式数据库、面向对象数据库等新型数据库是属于()。
设树T的度为4,其中度为1,2,3,4的节点个数分别为4,2,1,1。则T中叶子节点数为()。
将ER图转换到关系模式时,实体与联系都可以表示成()。
随机试题
下列有关存储器读写速度的顺序,正确的是( )。
证券公司操纵市场的行为会扰乱正常的( ),从而造成证券价格异常波动。
远期净敞口头寸的数量等于卖出的远期合约头寸减去买入的远期合约头寸。()
中国公民李四是一外商投资企业的中方雇员,2005年收入情况如下:(1)1~12月份每月取得由雇佣单位支付的工资、薪金15000元;(2)1-12月份每月取得由派遣单位支付的工资、薪金2500元;(3)4月份一次性取得稿费收入8
根据以下资料。回答下列问题。工业烟尘排放量占烟尘排放总量的比重最低的年份是:
伤心对于()相当于悲痛对于()
唐代对一品至九品的官员实行考课的标准是“四善二十七最”,其中的“四善”是指()。
______hotweathermaycauseserioushealthproblemsassociatedwithairpollution?______therewerecontroversiesontheissue
Newtechnologylinkstheworldasneverbefore.Ourplanethasshrunk.It’snowa"globlevillage"wherecountriesareonlyseco
Giventhechoicebetweenspendinganeveningwithfriendsandtakingextratimeforhisschool-work,AndyKliseadmitshewould
最新回复
(
0
)