首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-07-22
21
问题
有如下程序:
#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/35Np777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列选项中不符合良好程序设计风格的是
有如下程序:#include<iostream>usingnamespacestd;classDA{intk;public:DA(intx=1):k(x){}~DA(){cout<<k;}};intmain(
下列有关继承和派生的叙述中,正确的是
请定义一个函数名为A,返回值为int,没有参数的纯虚函数的定义是【】。
数据是指所有能输入到计算机之中并被计算机程序处理的()。
下面是“二维向量”vector2D的定义,其中作为成员函数重载的运算符“+”的功能是将两向量的分量x和y对应相加,然后返回作为相加结果的新对象。请填空补充完整。classvector2D{doublex;//x分量
“年龄在18-25之间”这种约束是属于数据库当中的
具有3个结点的二叉树有
数据结构分为逻辑结构和存储结构,下列数据结构中不属于存储结构的是
随机试题
A.单纯肋骨骨折B.多发性肋骨骨折胸壁软化C.胸壁挫伤D.闭合性气胸E.张力性气胸紫绀
A.GnRHB.雄激素C.孕激素D.抑制素E.LH
男性,35岁。因鼻塞、流涕3天伴咽痛、咳嗽两天就诊。自服“感冒通”等稍好转。无明显发热、咳痰及胸痛等。查体:T37.3℃,神志清,呼吸平顺,唇甲无发绀,咽稍红,双侧扁桃体无肿大。气管居中,双肺叩诊清音,未闻明显干湿啰音。患者行血常规示:WBC2.8
缺牙间隙多,倒凹大时适合采用平均倒凹法确定就位道。()
从国际上来看,委托指令有效期一般有当日有效与约定日有效两种。()
债券市场的功能主要体现在()。
《六朝那些事儿》一一寻绎魏晋六朝时代人物与事件的原委,但作者显然不是______,而是凭借对中国历史的熟谙,上下古今,议论风生,如指诸掌,加上采用的是比较新潮的语言,诙谐、生动,______,读来真不觉令人忘倦。填入划横线部分最恰当的一项是:
比如你自己,过去未尝不知道莫扎特的特色,但你对他并没有发生真正的共鸣;感之不深,自然爱之不切了;爱之不切,弹出来当然也不够味儿;而越是不够味儿,越是引不起你的兴趣。如此下去,你对一个音乐家的了解当然无从深入。以下哪项,从上述题干中推出最为恰当?
婴儿动作发展的规律以下表述不正确的是()【江西师范大学2014】
设A为3阶矩阵,α1,α2,α3是线性的无关3维列向量组,满足Aα1=α1+2α2+2α3,Aα2=2α1+α2+2α3,Aα3=2α1+2α2+α3.(1)求A的特征值.(2)判断A是否相似于对角矩阵?
最新回复
(
0
)