首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2019-05-22
25
问题
有如下程序:
#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
答案
A
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行类class的Type函数,输出Dog,然后输出speak,然后执行基类的Speak函数输出Voice,最后输出-,同理cat输出类似,所以结果为A选项正确。
转载请注明原文地址:https://jikaoti.com/ti/yrA0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#include<iostream>usingnamespacestd;classGA{public:virtualintf(){return1;}};classGB:pu
有如下程序:#include<iostream>usingnamespaeestd;classVAC{public:intf()COUSt{return3;}intf(){return5;}
A、 B、 C、 D、 B此题考查的是类的构造函数和析构函数。派生类构造函数的执行顺序为:首先调用基类的构造函数,调用顺序按它们被继承时说明的顺序;然后调用子对象的构造函数,调用顺序按它们在类中说明的顺序;最
A、 B、 C、 D、 B在面向对象程序设计中,允许作用于某个对象上的操作称为方法,方法是对象的动态属性。对象间的通信靠消息传递。对象是属性和方法的封装体,可以从祖先中继承属性和方法,但不是任何对象都具有继承
A、 B、 C、 D、 C线性表是一种线性结构,由n(n≥O)个元素组成,所以线性表可以是空表。但是在线性表中,第一个结点没有前件,最后一个结点没有后件,其他结点有且只有一个前件和后件,所以C是错误的。
A、 B、 C、 D、 Atest的构造函数重载,testA[3]调用test(intA)函数,然后删除时调用析构函数,故输出选项A。
在结构化分析使用的数据流图中,使用用______解释其中的图形元素。
某二叉树中有n个度为2的结点,则该二叉树中的叶子结点数为A)n+1B)n-1C)2nD)n/2
下列关于栈的叙述中,正确的选项是()。A)在栈中只能删除数据B)在栈中只能插入数据C)栈是先进先出的线性表D)栈是先进后出的线性表
若要对类BigNumber中重载的类型转换运算符long进行声明,下列选项中正确的是()。A)operatorlong()const;B)operatorlong(bigNumber);C)longoperatorlong()
随机试题
下列公共建筑内的房间,应保持相对周边区域正压的是:
下列各组字,象形、指事、会意、形声四种结构类型都具备的一组是()
A1~2个月B3~4个月C5~6个月D7~9个月E10~12个月添加肉末的月龄是
当病人出现血容量不足的症状时,说明在短期内体液丧失至少已达体重的
以下各项中,最低折旧年限为5年的固定资产是()。
近日,甲县公安局乙镇派出所深入辖区广泛开展消防安全宣传教育活动。活动中,民警前往辖区学校、卫生院、信用社等人员密集场所,通过发放宣传资料、面对面宣讲的方式,向辖区群众讲解火灾现场扑救、逃生等安全知识。乙镇派出所民警的做法体现了公安宣传教育工作的哪项要求?(
有研究表明,与眼睛相比,耳朵在分辨模式的微弱变化上具有独特的能力,据此发展起来的数据声音化技术,能帮助科学家们检测癌细胞,并探测来自太空的粒子。这蕴含的哲理是()。
当不同的规范性法律文件在同一事项上有不同规定时,法官通常遵循的原则有()(2012年一法综一第21题)
传统的交换机作为第二层设备,只能识别并转发(1)_____地址,要支持VLAN间的通信只能借助于具有(2)_____功能的网络设备。具有这种功能的设备有路由器和三层交换机。当用路由器解决VLAN通信时,路由器得到一个VLAN包后,根据目的IP地址,
HowTwoGreatConflictsHelpedtoChangeEuropeNinetyyearsagoonasunnymorninginNorthernFrance,somethinghappenedt
最新回复
(
0
)