首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2020-05-14
11
问题
有如下程序:
#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=newPiano("星空")时,调用派生类的GetType函数,得到type为钢琴,执行GetName时只能执行基类的这个函数,输出无名,所以输出钢琴-无名。选项D正确。
转载请注明原文地址:https://kaotiyun.com/show/Iv8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
如果一个模板声明时有类型形参表,则多个参数之间必须使用_______隔开,每个参数都必须重复使用关键字______。
设a=1;b=2;,则(a++)+b和a+++b这两个表达式的值分别为()。
有如下程序:classXX{protected:intk;public:XX(int=5):k(n){};~XX(){tout
有如下程序:#include<iostream>usingnamespacestd;classCA{public:CA(){cout<<’A’;}};classCB:priva
若有如下语句#include<iostream.h>voidmain(){intx=3:do{X=X-2;cout<<X;}while(!(--x)
下列关于线性链表的叙述中,正确的是()。A)各数据结点的存储空间可以不连续,但它们的存储顺序与逻辑顺序必须一致B)各数据结点的存储顺序与逻辑顺序可以不一致,但它们的存储空间必须连续C)进行插入与删除时,不需要移动表中的元素D)以上三
若有函数fun(x,y),并且已经使函数指针变量p指向函数fun,则使用p调用函数fun的方法是_____________。
在计算机软件系统的体系结构中,数据库管理系统位于用户和【】之间。
将E-R图转换为关系模式时,实体和联系都可以表示为( )。
在下列标识符中,不属于文件流类的标识符是
随机试题
根据专利法及相关规定,以下有关人民法院计算专利侵权赔偿数额的说法正确的是?
我国公务员交流的方式是
女性,22岁。查体:叩诊心界为烧瓶样,心音遥远,诊断为心包积液。患者不常见的临床表现包括
平胃散的组成药味是四君子汤的组成药味是
市场调查的程序基本可分为( )。
我国西南地区某地级市,其南部为丘陵,北部为山区,山区经济以农林为主。受地形条件影响,城镇主要集中在南部和中部地带,市域城镇化水平在35%左右,市域内现有大城市一个,县城6个,其他建制镇34个,规划为求市域内城镇均衡发展,在北部地区新设3个镇,市域交通规划
财政部门可以通过将会计从业资格证书注册登记管理与会计职业道德检查相结合的途径来实现会计职业道德建设。()
1588年,英国殖民者打败了______的“无敌舰队”,这是英国积极进行海外殖民扩张的开始。
(1)在考生文件夹中有工程文件sjt3.vbp,程序界面如图3-3所示。当在文本框中输入正整数N,单击“计算”命令按钮,进行计算。若N是奇数,计算l+3!+5!+……+N!,若N是偶数,计算1+3!+5!+……+(N+1)!。在给出的窗体文件中已经有了全
Lookattheorganizationchartbelow.Itshowstheresponsibilityofeachmanager.Whoseresponsibilitydoeseachsentence(11-1
最新回复
(
0
)