首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-05-06
29
问题
有如下程序:
#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
答案
C
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行基类的Type函数,输出Animal,然后输出speak,然后执行基类的Speak函数输出Voice,最后输出-,同理cat输出类似,所以结果为C选项正确。
转载请注明原文地址:https://kaotiyun.com/show/BWfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
请编写函数fun,其功能是:将M行N列的二维数组中的数据,按列的顺序依次放到一维数组中。一维数组中数据的个数存放在形参n所指的存储单元中。例如,若二维数组中的数据为333333334444
下列排序方法中,最坏情况下比较次数最少的是( )。
有如下类定义和对象定义:classA{public:A():data(0){}A(intx):data(x){}~A(){}intGetData()const{return
下列选项中,不是C++关键字的是
下列选项中,不是C++关键字的是
数据库系统的核心是()。
下列选项中不属于结构化程序设计方法的是()。
结构化程序所要求的基本结构不包括()。
某二叉树中有n个度为2的结点,则该二叉树中的叶子结点数为()。
设二叉树如下:则中序序列为
随机试题
在机体水液代谢过程中起主要作用的脏腑是
关于tRNA转录后加工,正确的是
下列哪个(些)临床症状提示为中度有机磷酸酯类中毒
除财政部门外,对单位会计实施监督的还有()
甲公司为增值税一般纳税人,2015年11月进口一批化妆品,海关核定的关税完税价格为70万元,甲公司缴纳进口关税7万元、进口消费税33万元。已知增值税税率为17%。甲公司进口该批化妆品应当缴纳的增值税税额为()。
情绪情感的定义是什么?
峰终定律是指人记忆某项事物的体验取决于开始和结束时的感觉。根据上述定义,下列选项没有运用到峰终定律的是()。
阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写对应栏内。【说明】下面的程序实现了类String的构造函数、析构函数和赋值函数。已知类String的原型为:classString{public:
•ReadthearticlebelowaboutNewtown.•Foreachquestion31-40,writeonewordonyourAnswerSheet.
Thebuildingnow______downisouroldofficebuilding.
最新回复
(
0
)