首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2015-07-22
52
问题
有如下程序:
#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://www.kaotiyun.com/show/5tNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
函数调用参数的传递方式有三种,值传递、【】和引用传递。
由于静态成员函数不属于某个具体的对象,但它属于某个【】,所以它没有this指针。
以/*开始,*/结束,在/*和*/之间的部分即为【】。
在表达式x-y中,“_”是作为非成员函数重载的运算符。若使用显式的函数调用代替直接使用运算符“_”,这个表达式还可表示为
下列关于this指针的叙述中,正确的是
下列叙述中正确的是
关于模板下列说法不正确的是()。
模板函数的真正代码是在()时候产生。
重载输入流运算符>>必须使用的原型为
关于类模板,下列表述不正确的是
随机试题
患者,男,29岁。今天下痢赤白黏冻,有时或见脓血便,腹痛,里急后重,肛门灼热,小便短赤。舌红,苔黄腻,脉滑数。治疗应首选
下列有关生存率估计的乘积极限法的描述中不正确的是
下列哪种情况应单独设置排风系统?(2003,79)
编制资产负债表的资料来源有()
纳税人购买自用的应税车辆,缴纳车辆购置税的期限是购买之日起()日内。(2014年)
购入交易性金融资产支付的交易费用。应计入投资收益。()
银行间的同业拆借属于()。
对中断概念的理解不正确的是()。
计算,其中D={(x,y)|一1≤x≤1,0≤y≤2}.
Teachersneedtobeawareoftheemotional,intellectual,andphysicalchangesthatyoungadultsexperience.Andtheyalsoneed
最新回复
(
0
)