首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-07-22
31
问题
有如下程序:
#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;classA{public:A(){cout<<"A";}~A(){cout<<"
下列叙述中正确的是
下列有关C++流的叙述中,错误的是
一间宿舍可住多个学生,则实体宿舍和学生之间的联系是( )。
在E.R图中,图形包括矩形框、菱形框、椭圆框。其中表示实体联系的是【】框。
类是一个支持集成的抽象数据类型,而对象是类的【】。
一个类可以同时继承多个类,称为多继承。下列关于多继承和虚基类的表述中,错误的是______。
对于常数据成员,下面描述正确的是()。
某二叉树T有n个节点,设按某种顺序对T中的每个节点进行编号,编号值为1,2,…n,且有如下性质:T中任一节点v,其编号等于左子树上的最小编号减1,而v的右子树的节点中,其最小编号等于v左子树上的节点的最大编号加1。此二叉树是按()顺序编号的。
具有3个结点的二叉树有
随机试题
消渴并发雀盲、耳聋、白内障者,治宜
我国税收法律关系权利主体中,纳税义务人的确定原则是()。
()是基金信息披露最根本、最重要的原则。
最容易产生企业控制权变动问题的融资方式是()。
下列行为中,()不属于持有、使用假币罪的范畴。
ThesymboloftheUSRepublicanPartyis______.
根据任务手段,可以将我国政府机构分为()等5种类型。
放眼世界、海纳百川,通过_______、消化、______,努力推动我国科学技术跨越式发展。填入画横线部分最恰当的一项是()。
Perhapsthemostinterestingthingaboutthephenomenonoftaboobehaviorishowitcanchange【1】theyearswithinthesamesocie
A、Studentsarenotrequiredtoattendregularclasslectures.B、Theprofessorvideotapesclasslecturesforreview.C、Classesar
最新回复
(
0
)