首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2019-07-10
27
问题
有如下程序:
#include
#include
using namespace std;
class Instrument{
public:
Instrument(string t="乐器",string n="无名"):type(t),name(n) { }
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,其中虚函数为GetName,当定义Instrument *pi=new Piano("星空")时,调用派生类的GetType函数,得到type为乐器,name为星空,所以输出乐器-星空。选项A正确。
转载请注明原文地址:https://kaotiyun.com/show/lW8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#include<iostream>usingnamespacestd;intmain(){cout.fill(’*’);cout.width(5);cout<<s
如果把类FriendClass定义为类TestClass的友元类,则应该在类TestClass的定义中加入语句______。
树是结点的集合,它的根结点的数目是()。
数据库DB、数据库系统DBS、数据库管理系统DBMS之间的关系是()。
一个队列的初始状态为空。现将元素A,B,C,D,E,F,5,4,3,2,1依次入队,然后再依次退队则元素退队的顺序为______。
不能重载的运算符是( )。
下列程序用于打印出ASCⅡ字符,其析构函数内的语句应为【 】。#include<iostream.h>#inelude<iomanip,h>template<classT>classArray{
下列有关类继承的叙述中,错误的是()。
下列符号中可以用作C++标识符的是()。
数据库设计分为需求分析阶段、______阶段、逻辑设计阶段、物理设计阶段、数据库实施阶段、数据库运行和维护阶段。
随机试题
“过伸牵引加手法复位治疗脊柱屈曲型骨折”最早见于
安装在机械排烟系统的管道上平时呈关闭状态,发生火灾时由电信号或手动开启,同时排烟风机启动开始排烟的是()。
账证核对是指将账簿记录与记账凭证进行核对。()
根据有关法律、法规,目前可受理劳动争议的调解组织有()。
Word默认的行间距是()。
下列关CSMA/CD协议的叙述中,错误的是_______。
设置参照完整性的目的是()。
Howmenfirstlearnedtoinventwordsisunknown:inotherwords,theoriginoflanguageisamystery.Allwereallyknowistha
Learningcanbeasolitaryact,but______otherscanhelpenrichourexperienceandnurtureourgrowth.
WhySmallCompaniesWillWininThisEconomyIjustheardastoryfromaclientthat’shardtobelievebuttrue.Inthe
最新回复
(
0
)