首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2015-07-22
40
问题
有如下程序:
#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=new Piano("星空")时,调用派生类的GetType函数,得到type为钢琴,name为星空,所以输出钢琴-星空。选项A正确。
转载请注明原文地址:https://kaotiyun.com/show/5tNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
以下程序的执行结果为()。#include<iostream.h>classSample{intn;public:Sample(inti){n=i;}operator++(){n+
定义如下枚举类型:enum{Monday,Tuesday,Wednesday,Thmsday,Friday=2);则下列语句正确的是()。
for(intx=0,y=0;!x&&y<=5;y++)语句执行循环的次数是()。
下列排序方法中,属于不稳定的排序方法是______。
下面函数返回数组中最大元素的下标,数组中元素个数为t,将程序补充完整。intfindmax(ints[],intt){intk,p;for(p=0,k=p;p<t;p++){if
下面程序的输出结果是【】。#include<iostream>usingnamespacestd;intd=1;fun(intp){staticintd=5;d+=p;
下列关于类和对象的叙述中,错误的是
如果友元函数重载一个运算符时,其参数表中没有任何参数则说明该运算符是
以下哪个不是C++语言中的有效标识符?
随机试题
子宫内膜癌首选的治疗方法是()
临床用于治疗消化性溃疡,属于奥美拉唑(–)–(S)–异构体的药物是()。
以下做法不符合相关法律规定的是()
下列倒装句中属于定语后置的一项是()。
在教学中,通过学生观察所学事物或教师语言的形象描述,引导学生形成所学事物、过程的清晰表象,丰富他们的感性认识,从而使他们能够正确地理解书本知识和发展认知能力。这体现的教学原则是()
在CPU中,常用来为ALU执行算术逻辑运算提供数据并暂存运算结果的寄存器是_______。
Awebcamisadigitalcamerathatsendsvideoimagestoothercomputerusers.It’saboutthe【C1】______ofagolfballandtyp
Theoriginsofbottledwatercanbe【B1】______backtotheearliest【B2】______.Wellawareofwater’shealthfacts,theRomansse
Theproblemofhowhealth-careresourcesshouldbeallocatedorapportioned,sothattheyaredistributedinboththemostjust
CanTonyBlairSavetheWorldofBooks?[A]AtthebeginningofAJourney,TonyBlairboaststhathehas"thesoulofarebel".
最新回复
(
0
)