首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument(string t=“乐器”,string n=“无名”):type(t),le(n){}
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument(string t=“乐器”,string n=“无名”):type(t),le(n){}
admin
2016-07-13
12
问题
有如下程序:
#include
#include
using namespace std;
class Instrument{
public:
Instrument(string t=“乐器”,string n=“无名”):type(t),le(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~tName()const{return nanle;}
};
int main(){
Itment*pi=new Piano(“星空”);
cout<
GetType()<<‘一’<
~tName();
delete pi;
return 0;
}
运行时的输出结果是( )。
选项
A、钢琴一星空
B、钢琴一无名
C、乐器一星空
D、乐器一无名
答案
A
解析
本题考查虚函数的运用,本题中基类Instrument,派生类Piano,其中虚函数为GetType,当定义Instrument*pi=new Piano(”星空”)时,调用派生类的GetType函数,得到type为钢琴,name为星空,所以输出钢琴一星空。选项A正确。
转载请注明原文地址:https://kaotiyun.com/show/3iNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
对于下面的程序,说法正确的是 #include<iostream.h> voidmain() {intx=3,y=4,z=2; if(X=y+z)cout<<"x=y+Z"; elsecout<<"x!=y+Z";}
有以下程序#include<iostream.h>voidss(char*s,chart){while(*s){if(*S==t)*s=t-’a’+’A’;s++;}}voidmain()
以下哪个基类中的成员函数表示纯虚函数?
有以下程序:#include<iostream>#include<string>usingnamespacestd;classY;classX{private:intx;
以下能对二维数组a进行正确初始化的语句是
对虚函数的调用有两种方式:【】和【】。
数据库系统阶段的数据具有较高独立性,数据独立性包括物理独立性和【】两个含义。
C++流中重载了运算符<<,它是一个()。
类Contain的定义如下:classContain{private:intx;protected:intz;public:classEmbed{
在下列枚举符号中,用来表示“相对于当前位置”文件定位方式的是
随机试题
课程在学校教育中的意义是什么?
美国联邦宪法正式生效于年_______。
A.肝细胞广泛水样变性、点状坏死B.肝细胞广泛脂肪变性、点状坏死C.肝细胞碎片状坏死D.肝细胞亚大块坏死E.肝细胞大块坏死
海关对于未取得报关从业资格的人员从事报关业务将()。
【2015中国银行】下列句子中有歧义的一句是()。
From:Stratton,Matthew(mstratton@market_research.org)To:Benson,Brad(bbenson@enterp.org)SentFriday.April1Subject:Conf
邓小平指出和平与( )是当代世界的两大主题。
下列哪一机关是我国的法律监督机关?()
下列叙述中正确的是
PHLEGMATIC:
最新回复
(
0
)