首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-05-14
30
问题
有如下程序:
#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全国计算机二级
相关试题推荐
有如下程序:#include<iostream>usingnamespacestd;classCA{public:CA(){cout<<’A’;}};classCB:priva
不合法的main函数命令行参数表示形式是()。
下列程序的输出结果是______。#include<iostream>usingnamespacestd;intmain(){chara[]="Hello,World";ch
下列关于线性链表的叙述中,正确的是()。A)各数据结点的存储空间可以不连续,但它们的存储顺序与逻辑顺序必须一致B)各数据结点的存储顺序与逻辑顺序可以不一致,但它们的存储空间必须连续C)进行插入与删除时,不需要移动表中的元素D)以上三
如果使用数组名称为函数参数,形实结合时,传递的是______。
对定义重载函数的下列要求中,()是错误的。
下列叙述中正确的是
下面关于C++语言变量的叙述错误的是
下列有关函数重载的叙述中,错误的是
随机试题
在一定压力下,单位体积的石油所溶解的天然气量,称为该气体的石油()。
消化管平滑肌对下列哪种刺激不敏感()
IwaswonderingthroughthestreetwhenIcaughtsightofastrangestore;therewasn’tanythingbutemptyshelvesatoneendof
Theboatsailedslowly,keeping______tothecoastasthemaninitwasafraidof______thedirection.
公司为获得一项工程合同,拟向工程发包方有关人员支付好处费8万元。公司市场部持公司董事长的批示到财务部领取该笔款项。该项支出不符合有关规定,但考虑到公司主要领导已做了批示,遂同意拨付该笔款项。下列对谢某的做法认定中,正确的是()。
立案监督即人民检察院对公安机关的刑事立案活动是否合法进行的监督。()
若x≥0,则的最小值为3,则α的值为().
从ENIAC开始到今天,可以将电子计算机的发展分为()等几个阶段。
查询最近30天的记录应使用()作为准则。
Educationlevelsarestronglyrelated______income.
最新回复
(
0
)