首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-05-06
66
问题
有如下程序:
#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/xGfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
数据库设计中,用E-R图来描述信息结构但不涉及信息在计算机中的表示,它属于数据库设计的()。
下列是重载乘法运算符的函数原型声明,其中错误的是()。
有如下程序:usingnamespacestd;classBoat;classCar{public:Car(inti):weight(i){}friendintTotal(constCar&c,constBoat&b);//
下列关于二叉树的叙述中,正确的是()。
C++系统预定了4个用于标准数据流的对象,下列选项中不属于此类对象的是()。
假设函数fun已经定义,其原型为“voidfun(inta,intb=7,char*p="*");”下列函数调用中错误的是()。
使用VC6打开考生文件夹下的源程序文件modi3.epp。此程序的运行结果为:InCDerive’sdisplay().b=1InCDerive2’sdisplay().b=2其中定义的类并不完整,按要求完成下列操作,
使用VC6打开考生文件夹下的源程序文件modi1.cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为:Number=8注意:错误的语句在//******error******的下面,修改该语句即可。1#includ
下列模式中,能够给出数据库物理存储结构与物理存取方法的是()。
下列关于虚函数的表述中,正确的是
随机试题
关于牵张反射的叙述,错误的是()。
下列行为不构成非法经营罪的是()。
下列高聚物加工制成的塑料杯中,哪种物质对身体无害?()
X线照片影像的要素不包括
生产、经营、储存、使用()的车间、商店、仓库不得与员工宿舍在同一座建筑物内,并应当与员工宿舍保持安全距离。
会计入员在处理业务过程中,要严格按事物的本来面目去反映,不掺杂个人主观意愿,不为他人意见所左右,公平正直,没有偏失,这体现了会计职业道德()的要求。
下列关于发放股票股利和股票分割的说法中,正确的有()。
我市有人不择手段仿造伪劣产品,这种坑害顾客、骗取钱财的不法行为,我们应该予以严厉打击。以上句子的语病类型是()。
设有两个事务Tl和T2,它们的并发操作如下所示,则正确的结论是一——。TlT2从DB读S从DB读SS=S-2S=S-4向DB回写S向DB回写S
ThewritingoftheConstitutionoftheUnitedStatesisanactofsuchgeniusthatphilosophersstillwonderatitsaccomplishme
最新回复
(
0
)