首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-05-14
38
问题
有如下程序:
#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全国计算机二级
相关试题推荐
下面程序的输出结果是()。#include<iostream.h>#include<string.h>voidmain(){charp1[10],p2[10];strcpy(p1,”abc”);
下面程序输出的结果为()。#include<iostream.h>voidfun(inta,intb){inttemp;temp=a;a=b;b=temp;}void
下列关于运算符重载的叙述中,错误的是
以下有关成员函数特征的叙述不正确的是
以下叙述中不正确的是
关于动态联编的下列叙述中,______是错误的。
下列叙述中正确的是
下列关于队列的叙述中正确的是
随机试题
A、milkB、thickC、biteD、listC
患者,女,27岁,孕3月,骑车不慎摔倒,阴道少量出血,腰腹坠痛,精神倦怠,脉滑无力,治疗最佳方剂是
设备运输合同客体是()。
下列传输设备测试项目中,测试值越小越好的是()。
(用户名:10;账套:012;操作日期:2011年1月31日)设置工资项目。项目名称:奖金类型:数字长度:8小数位数:2增减项:增项
()原则要求课税要素必须且只能由立法机关在法律中加以规定,无法律规定政府无权向私人征税。
假定,中国人民银行公布的货币供应量数据为(单位:亿元)(1)各项存款120048.33企业存款42685.74其中定期存款和自筹基建存款10329.08(亿元)
户籍不在本社区,但在本社区居住满()年以上的可以进行社区自治组织的选举登记。
ItisnoteasytotalkabouttheroleofthemassmediainthisoverwhelminglysignificantphaseinEuropeanhistory.Historyan
【B1】【B8】
最新回复
(
0
)