首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-05-06
33
问题
有如下程序:
#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/BWfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下面属于应用软件的是()。
有如下类声明和函数声明classBase{intm;public:intn;protected:intp;};classDer
有如下程序:#include<iostream>#include<string>usingnamespacestd;classPerson{public:Person(stringn):n
下面描述中不属于软件需求分析阶段任务的是
若有以下程序:#includeusingnamespacestd;intfun(){staticinti=0;ints=1;s+=i:i++;Feturn
已知枚举类型声明语句为:enumCOLOR{WHITE,YELLOW,GREEN=6,RED,BLACK=10};则枚举常量RED的值为
下列选项中不属于结构化程序设计方法的是()。
某二叉树共有7个结点,其中叶子结点只有1个,则该二叉树的深度为(假设根结点在第1层)()。
设树T的深度为4,其中度为1,2,3,4的结点个数分别为4,2,1,1。则T中的叶子结点数为()。
下列符号中,正确的C++标识符是()。
随机试题
一婴儿能独坐,并坐得很稳,但不会爬,能无意识地发出复音,认识生熟人,不能听懂自己的名字。人工喂养时,下列哪一点是不恰当的
患者积块软而不坚,固定不移,胀与痛并存,舌苔薄,脉沉实。其证候是
一流行性出血热传染源主要是( )霍乱传染源主要是( )
函数在x处的微分为()。
根据《水利工程质量监督管理规定》,工程质量检测是()的重要手段。
清洁工作日常管理由日检、月检及()组成,其中日检应覆盖小区主要室内外公共区域。
马斯洛需要层次论中的最高层次是()。
处理民族关系,我国坚持()的基本原则。
近年来的高考作文命题,在朝材料作文方向转变,旨在鼓励学生独立思考,自由表达,这是一个积极的改革方向,可是,材料作文却遭遇学生缺乏思考能力的________。去年高考作文,不独全国卷I的作文,其他一些省市的作文也被________。填入画横线部分最恰当的一
在VisualFoxPro中,报表的数据源不包括
最新回复
(
0
)