首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-07-22
65
问题
有如下程序:
#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
答案
D
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行基类的Type函数,输出Animal,然后输出speak,然后执行派生类的Speak函数输出Woof,最后输出-,同理cat输出类似,所以结果为D选项正确。
转载请注明原文地址:https://www.kaotiyun.com/show/JwNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
重载加法运算符“+”,其函数名是______。
有如下程序:#includeusingnamespacestd;classMonitor{public:Monitor(chart):type(t){}voidPrint()const{cout
以下程序的输出结果是#include<iostream.h>longfun(intn){longs;if(n=1||n=2)s=2;elses=n-fun(n-
如果类B继承了类A,则称类A为类B的基类,类B称为类A的【】。
关于虚函数下面说的正确的是()。
完全不考虑程序的内部结构和内部特征,而只是根据程序功能导出测试用例的测试方法是
对于模板定义关键字class和typename说法不正确的是()。
不能重载的运算符是
具有3个结点的二叉树有
下列数据结构中,能直接使用堆排序法进行排序的是
随机试题
全面发展教育
鉴别原发和继发性肾上腺皮质功能减退症最有价值的试验是A.血浆皮质醇测定B.血浆ACTH测定C.24小时尿皮质醇测定D.血清电解质测定E.尿17-羟、17-酮测定
A.Ⅰ期临床试验B.Ⅱ期临床试验C.Ⅲ期临床试验D.Ⅳ期临床试验E.生物等效性试验初步的临床药理学及人体安全性评价实验
非解剖式人工牙的牙尖斜度为
患者,女,40岁。不明原因的手足发麻,关节肿痛半年余。开始为手指小关节疼痛,后出现其他关节疼痛,呈对称性,遇寒或晨起时关节发硬,活动后减轻,舌苔薄白,脉浮紧。其最有意义的检查是
发绀性先天性心脏病麻醉诱导一般不用的药物为
上封层的类型有()。
教学过程是教师教、学生学的基本过程,具有若干环节,其中心环节是()。
南宋时期以擅画婴戏图著称的画家是________。
Highstreetshopsuseavarietyofmeanstoattractshoppers,suchasstrikingwindowdisplays,hugered"Sale"signsandspecia
最新回复
(
0
)