首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-05-14
48
问题
有如下程序:
#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、Dog speak Voice - Cat speak Voice
B、Dog speak Woof - Cat speak Miaow
C、Animal speak Voice - Animal speak Voice
D、Animal speak Woof - Animal speak Miaow
答案
B
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行类class的Type函数,输出Dog,然后输出speak,然后执行派生类的Speak函数输出Voice,最后输出-,同理cat输出类似,所以结果为B选项正确。
转载请注明原文地址:https://kaotiyun.com/show/mq8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
如果表达式y*x++中,“*”是作为成员函数重载的运算符,“++”是作为友元函数重载的运算符,采用运算符函数调用格式,该表达式还可表示为
函数swap(arr,n)可完成对arr数组从第1个元素到第n个元素两两交换。在运行调用函数中的语句后,a[0]和a[1]的值分别为【】。a[0]=1;a[1]=2;swap(a,2);
有如下程序:#include<iostream>usingnamespacestd;classCA{public:CA(){cout<<’A’;}};classCB:priva
请指出程序片段的语法错误______。
下面程序的输出结果是()。#include<iostream.h>#include<string.h>voidmain(){charp1[10],p2[10];strcpy(p1,”abc”);
下列叙述中,不正确的是()。
如果使用数组名称为函数参数,形实结合时,传递的是______。
下述关于数据库系统的叙述中正确的是
下列有关函数重载的叙述中,错误的是
下列叙述中正确的是
随机试题
疝修补术后宜取()
A.收缩压B.舒张压C.体循环平均充盈压D.平均动脉压E.中心静脉压右心房或胸腔大静脉内的压力称为
大豆是含蛋白质最多的植物性食物,也是我国人民膳食中优质蛋白质的来源。大豆中含量最多的不饱和脂肪酸是()。
模拟训练法的缺点不包括()。
洛可可美术代表画家有华托、贝尼尼、弗拉戈纳尔。()
李某夜间偷运毒品,何某见状上前抢劫,李某为了保护毒品,以暴力进行反抗,致何某重伤,李某的行为属于()。
简述日本现代设计的基本特征。
党的十八大提出了推进马克思主义中国化时代化大众化,推动中国特色社会主义理论体系进教材进课堂进头脑的重大课题。这一课题的提出
詹天佑说过:“各出所学,各尽所知,使国家富强不受外侮,足以自立于地球之上。”这句话强调在自觉维护国家利益时()
下列叙述中正确的是()。
最新回复
(
0
)