首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2015-06-27
39
问题
有如下程序:
#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=newPiano("星空")时,调用派生类的GetType函数,得到type为乐器,name为星空,所以输出乐器-星空。选项A正确。
转载请注明原文地址:https://kaotiyun.com/show/eJNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在函数中,可以用auto、extem、register和static四个关键字中的一个来说明变量的存储类型,如果不说明存储类型,则默认的存储类型是()。
下列程序的输出结果是【】。#include<iostream.h>#include<string.h>voidmain(){charb[30];strcpy(&b[0],"XY");
对于只在表的首、尾两端进行插入操作的线性表,宜采用的存储结构为【】。
假定MyClass为一个类,那么下列的函数说明中,()为该类的析构函数。
当需要将一个函数boolisnumber(charc)声明为内联函数时,则此内联函数的函数原型为()。
若类A和类B的定义如下:classA{public:inti,j;voidget();};classB:A{inti,j;protec
一个教师能开多门课程,一门课程有许多教师会开,实体课程与实体教师间是______。
用树形结构来表示实体之间联系的模型称为
数据结构作为计算机的一门学科,主要研究数据的逻辑结构、对各种数据结构进行的运算,以及
随机试题
关于烧伤创面的处理,下列哪一项是错误的
猩红热可见的舌改变是()
在人与人的沟通中,有一定的特殊性,下列哪些因素使得人们对同样的事情或谈话会有不同的解释和归因。美国管理的传统习惯是()。
当事人一方不履行非金钱债务或者履行非金钱债务不符合约定的,在下列何种情形下,对方不得要求履行?()
根据《个人所税法》规定,劳动报酬所得的个人所得税的税率为( )。
Euthanasiacanbeeitheractiveorpassive:(46)Activeeuthanasiameansthataphysicianorothermedicalpersonneltakeadelib
自顶向下的方法是一种系统化的方法,它是()的一种有机结合。
自然界では、繁殖力の最も強いすぐれたしゅが生き残ってるのがほうそくである。自然
Todaywe(havemade)great(achievements),(but)tomorrowweshallwinstill(great)victories.
Whichofthefollowingisconsideredalandmarkrulingininterracialmarriages?
最新回复
(
0
)