首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-09-05
32
问题
有如下程序:
#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
答案
D
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行基类的Type函数,输出Animal,然后输出speak,然后执行派生类的Speak函数输出Woof,最后输出-,同理cat输出类似,所以结果为D选项正确。
转载请注明原文地址:https://kaotiyun.com/show/Yb5p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列描述中,错误的是()。
下列关于模板的叙述中,错误的是()。
已知基类Employee只有一个构造函数,其定义如下:Employee::Employee(intn):id(n){}Manager是Employee的派生类,则下列对Manager的构造函数的定义中,正确的是()。
有如下程序:#includeusingnamespacestd;intmain(){voidfunction(doubleva1);doubleva1;
下列控制格式输入输出的操作符中,能够设置浮点数精度的是()。
下列叙述中正确的是()。
下列有关类继承的叙述中,错误的是()。
已知函数f的原型是voidf(int*a,long&b);,变量v1、v2的定义是:intv1;loongv2;下列调用语句中正确的是()。
下列关于C++函数的叙述中,正确的是()。
数据库设计的根本目标是要解决()。
随机试题
下列不属于按固定相形式分类的是()色谱。
下列哪项不属于高钾血症的主要表现【】
一级交易商可以直接向国库券发行部门承销困库券,包括___________、____________。
A、shutB、butC、brushD、successD
下列说法错误的是
在某工程网络计划中,已知工作M的总时差和自由时差分别为7天和5天,检查实际进度时发现该工作的持续时间延长了3天,说明此时工作M的实际进度()。
下列各项有关债权人会议表决权的表述中,正确的是()。
马克思主义政治经济学分析了社会资本简单再生产和扩大再生产的前提条件和实现条件,其中最核心的就是社会生产各部门之间必须保持一定的比例关系。以下哪些是马克思主义政治经济学关于社会资本再生产顺利进行的必然结论
Readthefollowingtextanddecidewhichanswerbestfitseachspace.Forquestions26~45,markoneletterA,B,CorDony
IrarelyweararaincoatbecauseIspendmostofmytimeinacar.
最新回复
(
0
)