首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-07-22
15
问题
有如下程序:
#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/x8Np777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序#include<iostream>usingnamespacestd;inta;intfun();intmain(){externinta;intb;
如果表达式y*x+十中,“*”是作为成员函数重载的运算符,“++”是作为友元函数重载的运算符,采用运算符函数调用格式,该表达式还可表示为
假设a、b均是整型变量,则表达式a=2,b=5,a++,b++,a+b值为【】。
软件生命周期中所花费用最多的阶段是
若以非成员函数形式,为类Bounce重载“!”运算符,其操作结果为一bool型数据,则该运算符重载函数的原型是【 】。
有如下程序:#include<iostream>usingnamespacestd;classCon{charID;public:Con():ID(W){cout<<l
若已经声明了函数原型“void fun(int a,double b=0.0);”,则下列重载函数声明中正确的是( )。
假定MyClass为一个类,则该类的拷贝初始化构造函数的声明语句为()。
有以下类定义:classMyClass{public:MyClass(){cout<<1;}};则执行语句MyClassa,b[2],*p[2];后,程序的输出结果是______。
关于虚函数,下列表述正确的是()。
随机试题
[*]
(2003年第53题)男性,47岁,10天前患急性前壁心肌梗死入院,一天来胸痛再发,呈持续性,在吸气时及仰卧位时加重,坐位或前倾位时可减轻。查体:体温37.5℃,血压正常,右肺底叩浊,呼吸音减弱,可闻及心包摩擦音,胸部X线片示右侧胸腔少量积液。WBC11
水利水电工程《注册建造师施工管理签章文件》目录表中,施工组织文件包含的文件名称有()报审表。
下列各项中,影响企业当期营业利润的是()。
根据支付结算法律制度的规定,下列票据当事人的签章中,不符合规定的是()。
“我们敢说日常所见的人中,十分之九都是他们的教育所决定的”。这一观点出自洛克的【】
约书亚.布朗博士说:“人类大脑可以捕捉到很微妙的征兆,它对危机预感的灵敏度远远超过我们先前的想象。”他认为,在人们可能犯错的情况下,前扣带脑皮质就会“有所反应”。在这里,博士的意思是:
简述中断的作用。
连续函数f(x)满足f(x)=3∫0xf(x一t)dt+2,则f(x)=________.
[*]
最新回复
(
0
)