首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-07-22
51
问题
有如下程序:
#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全国计算机二级
相关试题推荐
将x+y中的+运算符用友元函数重载应写为【】。
有以下类定义:classPoint{public:Point(intx=0,inty=0){_x=x;_y=y;}voidMove(intxOff,intyOff){_x+=xOff
有以下类定义:classMyClass{public:MyClass(){cout<<1;}};则执行语句MyClassa,b[2],*p[2];后,程序的输出结果是______。
已知:intm=10;在下列定义引用的语句中,正确的是______。
所有在函数中定义的变量,连同形式参数,都属于
下面是“二维向量”vector2D的定义,其中作为成员函数重载的运算符“+”的功能是将两向量的分量x和y对应相加,然后返回作为相加结果的新对象。请填空补充完整。classvector2D{doublex;//x分量
语句“ofstreamf("DATA.DAT",iosbase::appliosbase::binary);”的功能是建立流对象f,并试图打开文件DATA.DAT与之连接,而且()。
下列叙述中错误的是()。
在C++中,打开一个文件就是将这个文件与一个()建立关联;关闭一个文件就取消这种关联。
继承的方式有公有继承、私有继承和【】3种。
随机试题
形成人与自然和谐发展新格局,必须放在首位的是()。
一女性患者,诊断为巨大结节性甲状腺肿,在颈丛麻醉下行一侧甲状腺全切,一侧甲状腺次全切除术,术后第2天突然发生窒息,手足持续痉挛。此时首要的操作是
患者男,60岁。因“声音嘶哑半个月余伴咽痛”就诊,查体发现颈部可及2cm×4cm大小肿大淋巴结,颈部MRI提示:①右侧梨状窝新生物,侵及右侧声带,环状软骨部分受侵;②双侧颈部多个肿大淋巴结,最大径<6cm。患者经病检确诊为梨状窝低分化鳞癌,其他辅助检查
A、牙龈卟啉单孢菌B、粘性放线菌C、伴放线放线杆菌D、梭形杆菌和螺旋体E、中间普氏菌下列与牙周病最为密切的致病菌快速进展型牙周炎为
(2010)喷气式发动机尾喷管出口处,燃气流的温度为873K,流速为560m/s,蒸汽的等熵指数K=1.33,气体常数R=287.4J/(kg.K),则出口燃气流的马赫数为()。
下列选项中不属于结构化程序设计原则的是
Itispartly______thesummerdayislongerthateveryonecheersup.
ScientistsinIndiahaveinventedanewwaytoproduceelectricity.Theirinventiondoesnotgetitspowerfromoil,coaloroth
A、Theirdifferenteducationalbackgrounds.B、Changingattitudestowardnature.C、Chaostheoryanditsapplications.D、Thecurren
A、Howstudentsmanagetocompletetheirstudiessuccessfully.B、Howfamiliesmanagetodealwithvariouskindsofchallengingor
最新回复
(
0
)