首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-07-22
48
问题
有如下程序:
#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输出类似,所以结果为B选项正确。
转载请注明原文地址:https://kaotiyun.com/show/EuNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
假设用一个长度为50的数组(数组元素的下标从0到49)作为栈的存储空间,栈底指针bottom指向栈底元素,栈顶指针top指向栈顶元素,如果bottom=49,top=30(数组下标),则栈中具有【】个元素。
通过派生类的对象可直接访问其
派生类对基类的继承有三种方式:______、______,保护继承。
下面对于友元函数描述正确的是()。
关于虚函数下面说的正确的是()。
C++语言中类定义中默认的访问权限是
关键字ASC和DESC分别表示【】的含义。
下述关于数据库系统的叙述中正确的是
一个关系中属性个数为1时,称此关系为
下列C++标点符号中表示一条预处理命令开始的是()。
随机试题
苦杏仁酶可以使下列哪些糖的苷键酶解
主动转运的特点有()。
甲去商店买东西,售货员乙误将单价为400元的商品以40元的价款卖于甲,则下列说法正确的是()。
动态投资回收期是指项目以()抵偿全部投资所需的时间。
下列选项中,汽车产量同比增速最低的是()。
公安行政复议是公安机关内部进行自我监督的有效法律途径。()
下列各句中,存在语病的一项是()。
从所给的四个选项中,选择最合适的一个填入问号处,使之呈现一定的规律性:
J2SDK的基本命令中用于Java类文件归档的是______。
Computersarepermeatingalmosteveryaspectofourlives,includingmanyareaspreviouslyuntouchedbytechnology.【B1】Butunl
最新回复
(
0
)