首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-07-22
50
问题
有如下程序:
#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
答案
C
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行基类的Type函数,输出Animal,然后输出speak,然后执行基类的Speak函数输出Voice,最后输出-,同理cat输出类似,所以结果为C选项正确。
转载请注明原文地址:https://kaotiyun.com/show/x8Np777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下面关于虚函数的描述中正确的是
将E-R图转换到关系模式时,实体与联系都可以表示成
下列叙述中正确的是
下列选项中不属于软件生命周期开发阶段任务的是
己知一个函数的原型是:intfn(doublex);若要以5.27为实参调用该函数,应使用表达式【】。
软件调试的目的是
已知表达式++a中的“++”是作为成员函数重载的运算符,则与++a等效的运算符函数调用形式为
类模板template<classT>classx(…),其中,友元函数f成为从该类模板实例化的每个模板类的友元,则其说明应为()。
某二叉树T有n个节点,设按某种顺序对T中的每个节点进行编号,编号值为1,2,…n,且有如下性质:T中任一节点v,其编号等于左子树上的最小编号减1,而v的右子树的节点中,其最小编号等于v左子树上的节点的最大编号加1。此二叉树是按()顺序编号的。
设有以下变量定义,并已赋确定的值:charw;intx;floaty;doublez;则表达式:w*x+z-y所求得的数据类型为()。
随机试题
A.classifiedB.conductedC.dietingD.earlierE.laterF.lessG.lifeH.linkedI.obeseJ.obse
各国普遍通过——等国内法规范,具体规定国际经济争端的调解、仲裁或司法解决方式。()
Anewstudyfoundthatinner-citykidslivinginneighborhoodswithmoregreenspacegainedabout13%lessweightoveratwo-yea
会阴
获得性免疫缺陷综合征(AIDS)的病原体是
下面有关计算机操作系统的叙述中,不正确的是()。
“月老”族指的是月初是“月光”族,大手大脚地花自己的钱;月末变成了“啃老”族,自己的钱花光了,只好向父母伸手要钱。根据上述定义,下列属于“月老”族的表现的是()。
2015年保险公司原保险保费收入24282.52亿元,同比增长20.00%,比上一年高2.51%。其中,产险业务原保险保费收入7994.97亿元,同比增长10.99%;寿险业务原保险保费收入13241.52亿元,同比增长21.46%;健康险业务原保险保费收
在进行数据库物理设计时,为了保证系统性能,需要综合考虑所选择的数据库管理系统的特性及软硬件具体情况。下列关于数据库物理设计的说法,错误的是()。
HowtoChooseaCollege?I.Student-facultyratio—Thelowertheratios,themore【T1】______youwillget—Healthy
最新回复
(
0
)