首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespaee std; class Instrument{ public: Instrument(string t="乐器",string
有如下程序: #include #include using namespaee std; class Instrument{ public: Instrument(string t="乐器",string
admin
2016-08-19
32
问题
有如下程序:
#include
#include
using namespaee 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://kaotiyun.com/show/FpNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
若有以下程序:#include<iostream>usingnamespacestd;classpoint{private:intx,y;public:point(
有以下程序:#include<iostream>#include<string>usingnamespacestd;intmain(){charb1[8]="abcdefg";
在关系模型中,把数据看成一个二维表,每一个二维表称为一个【】。
下列关于类的访问权限的描述中,()是错误的。
数据库系统的核心是______.
.、.*、->、::、?:这五个运算符______重载。
下面叙述错误的是()。
在多继承中,公有派生和私有派生对于基类成员在派生类中的可访问性与单继承的规则()。
软件需求分析阶段的工作,可以分为四个方面:需求获取,需求分析,编写需求规格说明书,以及
下列函数的功能是判断字符串str是否对称,对称则返回true,否则返回false。请在横线处填上适当内容,实现该函数。Boo1fun(char*str){inti=0,j=0;while(str[j]j++;f
随机试题
Atthe________stagenegationissimplyexpressedbysinglewordswithnegativemeaning.()
男性,45岁,上腹痛3年余,周期性发作。近1周呈持续性痛,左上腹局限性压痛。钡餐见胃角部龛影,直径1.0cm本病例的诊断是
患者,男,67岁。热结阴伤,大便燥结。宜用大黄配伍
有头疽初起症状多见
砖砌体砌筑方法,下列哪条是不正确的?[2004年第26题]
截水帷幕目前常用的形式有()。
下列关于“比较优势原则”的表述中,A的有()。
在平面直角坐标系中,在x∈(0,1),y∈(0,1)的区域内任取一点,则点恰好在以原点为中心、以1为半径的圆内的概率为().
对于图书管理数据库,检索藏书中比高等教育出版社的所有图书的书价更高的书。下面SQL语句正确的是______。SELECT*FROM图书WHERE单价>ALL;对于图书管理数据库,检索所有藏书的书名和出版单位。下面SQL语句正确的是__
Upto80percentoftimespentonlineatworkiswasted,accordingtoanewstudyfromKansasStateUniversity.Itsuggeststhat
最新回复
(
0
)