首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-07-22
35
问题
有如下程序:
#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://kaotiyun.com/show/xrNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
已知程序中已经定义了函数test,其原型是inttest(int,int,int);,则下列重载形式中正确的是______。
当数据的物理结构(存储结构、存取方式等)改变时,不影响数据库的逻辑结构,从而不致引起应用程序的变化,这是指数据的【】。
当输入“Thankyou”时下列程序的输出结果为()。#include<iostream.h>#include<iomanip.h>voidmain(){charli
通常的拷贝初始化构造函数的参数是()。
下列程序在构造函数和析构函数中申请和释放类的数据成员int*a,申请时使用形参b初始化a,请填空。classA{public:A(intb);~A();private:
继承的方式有公有继承、私有继承和【】种。
语句“ofstreamf("DATA.DAT",iosbase::appliosbase::binary);”的功能是建立流对象f,并试图打开文件DATA.DAT与之连接,而且()。
下列叙述中错误的是()。
下面的叙述中,不符合赋值兼容规则的是()。
继承的方式有公有继承、私有继承和【】3种。
随机试题
设(x≠-1),则f’(1)=________
患者男,13岁。舌有时出现刺激痛近1年,检查见舌背有3块光滑的红色剥脱区,微凹陷,直径5~10mm,有两块已相连,剥脱区边缘为白色微高起的弧形或椭圆形所包绕,宽约1.5mm。可诊断为
发行人股票发行前,中国证监会审核员应要求()对公司在通过发审会审核后是否发生重大事项分别出具专业意见。Ⅰ.发行人律师Ⅱ.保荐机构Ⅲ.发行人会计师Ⅳ.发行人住所地证监局
根据成本性态,在一定时期一定业务量范围之内,职工培训费一般属于()。
一个流浪汉喝着冰红茶,望着元宵节漫天绽放的烟花,笑容比烟花还要灿烂。此照片仅一天就被转发超过了6万次。网友被如此简单的笑容感染,都叫他“微笑哥”。新年伊始,《爱上这身无分文的日子》《一年不花钱:我的无货币主义生活》《辞职,去旅行》……一大批教人如何“穷快活
Itseemstomethatthemainrequirementofaninternationallanguageisthatit______easilylearned.
下列4条叙述中,正确的一条是
Her_____asaneconomisthasbeenreinforcedbyhersuccessfulfightagainstinflation.
Someindividualsandcitizens’groupshaveexpressedconcernaboutthelevelofviolenceintelevisionprograms,particularlyin
OneofthestrangestandmostfascinatingthingsaboutScotlandistheLochNessMonster.Somepeoplebelieveinthemonster’s【B
最新回复
(
0
)