首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-09-05
51
问题
有如下程序:
#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/lpfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#include<iostream>usingnamespacestd;classsample{private:intx,y;public:sample(inti,intj){x=i:y=j;}voidd
下面叙述中错误的是()。
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,其中有点类Point和线段类Line和主函数main的定义,程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出应为:
下列关于栈的叙述正确的是( )。
执行下列语句段后,输出字符“*”的个数是()。for(inti=50;i>1;i-=2)cout
要建立文件流并打开当前目录下的文件file.dat用于输入,下列语句中错误的是()。
关于关键字class和typename,下列表述中正确的是()。
以下关键字不能用来声明类的访问权限的是()。
如果有以下定义及初始化:inta=3,*p=&a;则由此可以推断,*p的值是()。
如果有以下定义及初始化:inta=3,*p=&a;则由此可以推断,*p的值是()。
随机试题
CT2系统的本地集中器负责账号处理、收费。()
《五代史伶官传序》中,作者重点评论的历史人物是()
党参粉末中可见
如题50图所示的四杆机构中,已知杆长尺寸lAB=85mm,lBC=100mm,lCD=115mm,lAD=120mm,,其运动副为整转副的是()。
下列选项属于发包人应当提供的设计依据文件和资料的有( )。
民用危险物品包括()。
五项原则之于国家关系,就像空气与水之于人类生存______,同样,有国家存在,就有国家间的矛盾、分歧和利益差异存在,就需要妥善解决。______或者老死不相往来,都不应成为国家关系的选项。依次填入画横线部分最恰当的一项是()。
评清末保路运动。
下列事项中,属于会计政策变更的是()。
A、It’sbecausetherearemanydevelopingnations.B、It’sbecausepeopleusetoomanyman-madematerials.C、It’sbecausewehave
最新回复
(
0
)