首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-05-14
44
问题
有如下程序:
#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/mq8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
以下内容不属于算法程序所占的存储空间的是()。
有如下类声明:class1.estClass1{intk:public:voidset(intn){k=n;}intget()const{returnk;}};
下面程序应能对两个整型变量的值进行交换。以下正确的说法是 #include<iostream.h> voidswap(intp,intq) {intt; t=p; p=q; q=t;} voidmain()
下面程序的输出结果是()。#include<iostream.h>#include<string.h>voidmain(){charp1[10],p2[10];strcpy(p1,”abc”);
如果表达式x=y*z中的“*”是作为成员函数重的运算符,采用运算符函数调用格式,该表达式还可以表示为______。
下列关于关系运算的叙述中正确的是
下面关于C++语言变量的叙述错误的是
关于动态联编的下列叙述中,______是错误的。
随机试题
下列选项中,属于高绩效工作系统内容的是()。
销售人员不应一味消极适应环境变化。这充分表明销售机会具有()
道路交通安全设施中,()可以有效地排除横向干扰,避免由此产生的交通延误或交通事故。
假设一个项目:有70%的可能在一年内让他的投资加倍,30%可能让他的投资减半。则下列说法正确的是( )。
下一级政府能做的事一般不交上一级政府,上一级政府只处理下一级地方政府不能处理的事务,体现了界定政府职责范围的( )。
企业在报告期内出售、购买子公司,期末在编制合并资产负债表时,必须调整合并资产负债表的年初余额。()
(53)指直接作用于人的感觉器官,使人产生直接感觉的媒体。
Ourshasbecomeasocietyofemployees.AhundredyearsorsoagoonlyoneoutofeveryfiveAmericansatworkwasemployed,i.
Iftheoldmaximthatthecustomerisalwaysrightstillhasmeaning,thentheairlinesthatplytheworld’sbusiestairrouteb
Mostearthquakesoccurwithintheupper15milesoftheearth’ssurface.Butearthquakescananddooccuratalldepthstoabout
最新回复
(
0
)