首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
32
问题
有如下程序:
#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>usingnamespacestd;classMyClass{public:MyClass();~MyClass();v
执行下列语句后,c3中的值为【】 intc1=1,c2=2,c3;c3=1.0/c2*c1;
下列叙述中,不属于数据库系统的是
若有以下程序:#include<iostream>usingnamespacestd;classmyClass{private:intvar;public:myClass
友元类的所有成员函数都是另一个类的【】。
关系数据库的关系演算语言是以【】为基础的DML语言。
若有以下程序:#include<iostream>usingnamespacestd;classBase{intx;protected:inty;public:
下列叙述中,正确的是()。
随机试题
TheFrenchgovernmentistobanstudentsfromusingmobilephonesinthecountry’sprimary,juniorandmiddleschools.Children
名誉市长制,又称()。
颈段椎管狭窄,是指椎管前后径小于
功用为清热解毒,消肿溃坚,活血止痛的方剂是
关于我国立法程序,下列哪一选项的表述不能成立?
房地产开发项目的建设过程是指()的持续时间。
著名的需要层次理论提出者是心理学家()。
邓小平指出“计划经济不等于社会主义,资本主义也有计划;市场经济不等于资本主义,社会主义也有市场”这一论断表明()。
机动车在高速公路上发生故障时,警告标志应当设置的故障车()方向150米以外。
立冬日,南部沿海地区仍处在夏季的主要原因是:
最新回复
(
0
)