首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-07-22
47
问题
有如下程序:
#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://www.kaotiyun.com/show/35Np777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下定义:classMA{intvalue;public:MA(intn=0):value(n){}};MA*ta,tb;其中MA类的对象名标识符是【】。
以下程序的输出结果是【】。#include<iostream.h>classobject{private:intval;public:
将x+y中的+运算符用友元函数重载应写为【】。
软件是一种()。
不能重载的运算符是
如果一个模板声明时有类型形参表,则多个参数之间必须使用______隔开,每个参数都必须重复使用关键字______。
下列选项中,不属于模块间耦合的是
以下程序中函数scmp的功能是返回形参指针s1和s2所指字符串中较小字符串的首地址。#include<string>char*scmp(char*s1,char*s2){if(strc
下列对派生类的表述中,错误的是()。
随机试题
被申请人不履行法定职责的,决定其在一定期限内履行()
“名人传”中的《贝多芬传》和《托尔斯泰传》均是法国作家________的代表作品。
左心室与右心室在解剖上的主要区别是
A.粉碎成原粉B.回流法C.提取有效成分D.提取挥发油E.煎煮法含用量少的贵重药材片剂原料最适宜的处理方法为
A.交界痣B.皮内痣C.混合痣D.皮脂腺痣E.鲜红癍痣1岁男性患者,面部发现一直径1cm的褐色皮肤肿物,并有数根毛发生长。最有可能的疾病是
为了保存浆膜腔积液中化学成分,应加入的抗凝剂为
女性,35岁,在甲状腺次全切除后4小时,突感呼吸困难、颈部肿胀,口唇发绀,紧急处理第一步应
某市拟建一综合建筑,地下3层,地上32层,建筑高度为98m,每层建筑面积为10000m2;地下二、三层为汽车库,室内净高2.4m,可停车数量为650辆,地下一层主要经营餐饮,地上一至六层为商场,七至三十二层为办公楼。该建筑内设有室内外消火栓系统、自动喷水
ThestructuralapproachtotheanalysisoflanguagewasstartedbytheSwisslinguist______inthebeginningofthetwentiethc
NewresearchconductedbybrainresearcherAviKarnioftheUniversityofHaifainIsraelexploresthepossibilitythatnapshel
最新回复
(
0
)