首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-05-14
55
问题
有如下程序:
#include
#include
using namespace std;
class Animal{
public:
virtual string GetType() const { return "Animal"; }
virtual string GetVoice() const { return "Voice"; }
};
class Dog:public Animal{
public:
string GetType() const { return "Dog"; }
string GetVoice() const { return "Woof"; }
};
class Cat:public Animal{
public:
string GetType() const { return "Cat"; }
string GetVoice() const { return "Miaow"; }
};
void Type(Animal a) { cout<
void Speak(Animal& a) { cout<
int main() {
Dog d; Type(d); cout<<" speak "; Speak(d); cout<<" - ";
Cat c; Type(c); cout<<" speak "; Speak(c); cout<
return 0;
}
运行时的输出结果是
选项
A、DogspeakVoice-CatspeakVoice
B、DogspeakWoof-CatspeakMiaow
C、AnimalspeakVoice-AnimalspeakVoice
D、AnimalspeakWoof-AnimalspeakMiaow
答案
D
解析
本题考查虚函数的运用,本题中定义Dogd;Type(d)时,执行基类的Type函数,输出Animal,然后输出speak,然后执行派生类的Speak函数输出Woof,最后输出-,同理cat输出类似,所以结果为D选项正确。
转载请注明原文地址:https://kaotiyun.com/show/Og8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在下面表达式中,不表示虚继承的是()。
若有以下函数调用语句:f(m+n,x+y,f(m+n,z,(x,y)));在此函数调用语句中实参的个数是()。
执行语句for(i=1++<4;);,后变量i的值是
下列代码段声明了3个类:classPerson();classStudent:publicPerson{};classUndergraduate:Student{};下列关于这些类之间关系的描述中,错误的是()。
有如下程序:#include<iostream.h>voidmain(){intx=2,y=3,a,b,c,d;a=(x++>=--y);b=(x==++y);c=(x--!=y);d=(++x>y--);Cout<<a<<b<<c<
以下程序中,错误的行为①#include<iostream.h>②classA③{④public:⑤intn=2;⑥A(intval){cout<<val<<end1;}
在深度为7的满二叉树中,叶子结点的个数为
长度为n的顺序存储线性表中,当在任何位置上插入一个元素概率都相等时,插入一个元素所需移动元素的平均个数为【】。
某二叉树中度为2的结点有18个,则该二又树中有______个叶子结点。
随机试题
公安机关因侦查犯罪的需要,可以采取技术侦查措施。采用技术侦查措施适用的要件不包括()。
关于合议制度,下列说法错误的是;
我国巧虎公司欲将其“巧虎”商标在海关总署申请备案,以利于保护其知识产权,根据我国《知识产权海关保护条例》,下列说法错误的是:()
对某在用钢筋混凝土桥梁进行结构材质状况无损检测,请回答以下相关问题。采用超声法检测结构混凝土的内部缺陷,下列叙述正确的包括()。
国家对进口玩具实行加施( )的管理。
理智型问题客户具有很强的推理能力和判断能力,在深思熟虑后才能决定,善于控制自己的情感,因此理财服务人员在处理理智型客户的投诉时应该()。
首先提出“普及教育”口号的是在()时期。
按通信类型分,2012年1—5月累计完成投资额排在第五位的行业其投资额占合计的比重是:
数据库管理系统是
Asimplecomputerprogramthatteacheschildrentodistinguishbetweensoundscandramatically(1)______theirlisteningskills.
最新回复
(
0
)