首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2021-09-05
43
问题
有如下程序:
#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/db5p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列叙述中正确的是()。
下列函数模版中的定义中,合法的是()。
在学生管理的关系数据库中,存取一个学生信息的数据单位是()。
下列关于基类和派生类关系的叙述中,正确的是()。
有如下定义:inta[5]={1,3,5,7,9},*p=a;下列表达式中不能得到数值5的是()。
下列数据结构中,能用二分法进行查找的是()。
有三个关系R、S和T如下:则由关系R和S得到关系T的操作是()。
下列关于构造函数的描述中,错误的是()。
已知表达式++a中的“++"是作为成员函数重载的运算符,则与++a等效的运算符函数调用形式为()。
软件测试的目的是( )。
随机试题
在依法扣除劳动者工资后,剩余部分的工资低于当地工资标准的,则按_________。
法律文书中的理由有哪些具体要求?
简述咨询公司在方案实施阶段的工作步骤。
A.进口检验B.抽查性检验C.委托检验D.复验E.注册检验根据药品监督管理部门抽检计划,对药品生产、经营、使用单位抽出样品实施的检验是()。
居住区内下列哪种情况采用明沟排地面水是错误的?[2004年第75题]
股票基金的特点是( )。
恩格斯指出:“世界不是既成事物的集合体,而是过程的集合体。”这是唯物辩证法的“一个伟大的基本思想”。事物发展的过程从内容上看是()
ReadthefollowingtextandanswerthequestionsbychoosingthemostsuitablesubheadingfromthelistA-Gforeachnumberedpa
有以下程序:#include<stdio.h>main()char*p[]={"3697","2548"};inti,j;longnum=0;for(i=0;i<2;i++){
I’dliketotalkabout(1)inEnglandandWales,andinEnglandandWalesthereare(2)ofcouncil.Forinstance,ifIcouldtak
最新回复
(
0
)