首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
39
问题
有如下程序:
#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() {inti; inta[3][3]={1,2,3,4,5,6,7,8,9}; for(i=0;i<3;i++) cout<<a[i
有如下的程序:#include<iostream>#include<fstream>usingnamespacestd;intmain(){ofstreamoutf("D:\\temp.t
以下程序运行后的输出结果是【】。#include<iostream>#include<string>usingnamespacestd;classY;classX{intx;
设有以下定义和程序:#include<iostream.h>classA1{public:voidshowl(){cout<<"classA1"<<end1;
有以下程序:#include<iostream>usingnamespacestd;classMyClass{public:MyClass();~MyClass();v
在重载运算符函数时,下面()。运算符必须重载为类成员函数形式。
下列运算符中哪些是不能够被重载的?
c++流中重载了运算符<<,它是一个
每个以符号______开头的行,为编译预处理行。
随机试题
关于阑尾腺癌正确的是
痿症见手足痿弱,形体瘦削,肌肤甲错者为瘀血久留,可用
关于菌斑说法正确的是
请指出下列疾病的特征性X线片变化( )
不能补充血糖的生化过程是
航空运输中,托运人可以对航空货运单上除()以外的其他条款向承运人提出更改。
关于公积金个人住房贷款和商业银行自营性个人住房贷款的区别,下列泡法正确的是()。
甲公司2007年经营性流动资产300万元,经营性流动负债200万元,金融负债180万元,金融资产20万元,经营长期资产增加800万元,经营长期负债180万元,则该公司投资资本为()万元。
PASSAGEONEAccordingtothepassage,whatdidDicksufferintheworkhouse?
PeopleallovertheworldwritetoBigBen.They【C1】______sendbirthdaypresents.BigBenisnota【C2】______.It’saclock!
最新回复
(
0
)