首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-06-29
31
问题
有如下程序:
#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/3syp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
结构化程序设计中,下面对goto语句使用描述正确的是
在下列选项中,不允许作为C++标识符的是
有如下类声明和函数声明classBase{intm;public:intn;protected:intp;};classDer
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。其中有向量基类VectorBase、向量类Vector和零向量类ZeroVector的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。该程序正确输出结果应为:(1.2.
有如下类定义:classMyClass{public:MyClass(doubled=0.0):val(d){}______________/
若已经定义了如下的函数:intf(inti,charc);则下列函数中可以作为此函数的重载函数的是
下列关于栈叙述正确的是( )。
下列关于运算符重载的描述中,正确的是()。
将E-R图转换为关系模式时,实体和联系都可以表示为( )。
设c1和c2是类MyClass的对象,若将前缀运算符"--"和运算符"/"作为类MyClass的友元函数重载,则表达式--c1/c2等价于
随机试题
对病人的适应性行为进行奖励的方法是
最常见的妄想类型是
【背景资料】某吹填工程,吹填区总面积2.5km3、吹填总容量2000万m3,分为A、B、C三个区进行吹填。A区吹填面积0.9km3、吹填容量750万m3;B区吹填面积0.75km2、吹填容量550万m3;C区吹填面积0.85km2、吹填容量700
传统折中理论认为,公司的加权平均资本成本先升后降,存在一个最优的资本结构。()
小玲性情沉静,情感发生缓慢而微弱,不外露,忍耐力强,她的气质类型属于()。
简述小学体育教学的一般性原则。
如果一个复选框被选中,则
计算斐波那契数列第n项的函数定义如下:intfib(intn){if.(n==0)return1;elseif(n==1)return2;elsereturnfib(n-1)+fib(n-2);}若执行函
在深度为5的满二叉树中,叶子结点的个数为()。
EversinceALGoreinventedit,theInternethasbeenaparadiseforthosewithacreativeattitudetofacts.Students,forexam
最新回复
(
0
)