首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2019-03-05
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
答案
A
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行类class的Type函数,输出Dog,然后输出speak,然后执行基类的Speak函数输出Voice,最后输出-,同理cat输出类似,所以结果为A选项正确。
转载请注明原文地址:https://kaotiyun.com/show/LqAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
以下选项中与k=n++;完全等价的表达式是
以下的for循环for(x=0,y=0;(y!=123)&&(x<4);x++);
下列数据结构中按“先进先出”原则组织数据的是
实体是信息世界中广泛使用的一个术语,它用于表示
下面关于运算符重载的描述错误的是()。
下列叙述中正确的是()。
有如下程序:#include<iostream>usingnamcspacestd;intmain(){voidfunction(doubleval);doubleval;function(v
类模板不同于函数模板,类模板只可用______型参数。
栈C最多能容纳4个元素,现有6个元素按A、B、C、D、E、F的顺序进栈,下列哪个序列不是可能的出栈序列()。
在函数中,可以用auto、extern、register和static这四个关键字中的一个来说明变量的存储类型,如果不说明存储类型,则默认的存储类型是()。
随机试题
这个标志是何含义?
试述在述谓结构中,谓词是处于支配地位的核心成分。
脑干网状结构上行激动系统的特点有()。
什么是蒸汽系统的“水击”现象,说明防止“水击”现象的措施。
根据最低收益法,客户要求的收益越高,说明其风险厌恶程度越高。()
ABC公司是一零售业上市公司,请你协助完成2003年的盈利预测工作,上年度的财务报表如下:其他财务信息如下:(1)下一年度的销售收入预计为1512万元;(2)预计毛利率上升5个百分点;(3)预计经营和管理费的变动部分与销售收入
求助者:男,18岁,高二学生。案例介绍:求助者上高二的时候,和临班的一个女生好上了,后来总是好好分分,求助者觉得她很自我,太任性,老是和她对着干,摸不透她的脾气,感觉谈恋爱像在乞讨,但又忍不住和她在一起。半年前成绩下降得很厉害,怕影响高考,和她彻
小学生学习方式有哪些基本类型?
TheAlaskaGovernorhastakenthefollowingstepsinresponsetothePrudhoeBayoilfieldshutdownEXCEPT.
Forthispart,youareallowed30minutestowriteashortessayentitledAboutKeepingIndoors.Youshouldwriteatleast150w
最新回复
(
0
)