首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-09-05
40
问题
有如下程序:
#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、DogspeakVoice-CatspeakVoice
B、DogspeakWoof-CatspeakMiaow
C、AnimalspeakVoice-AnimalspeakVoice
D、AnimalspeakWoof-AnimalspeakMiaow
答案
D
解析
本题考查虚函数的运用,本题中定义Dogd;Type(d)时,执行基类的Type函数,输出Animal,然后输出speak,然后执行派生类的Speak函数输出Woof,最后输出-,同理cat输出类似,所以结果为D选项正确。
转载请注明原文地址:https://kaotiyun.com/show/AI5p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在面向对象方法中,不属于“对象”基本特点的是()。
如下函数的作用是以双倍行距输出文件:voiddouble_space(ifstream&f,ofstream&t){charc;whilc(_________){;_________if(c==
下列程序的输出结果是()。#include<iostream>usingnamespacestd;template<typenameT>Tfun(Ta,Tb){return(a<=b)?a:b;}intmain(){co
下列关于C++流的描述中,错误的是()。
如果派生类以protected方式继承基类,则原基类的protected成员和public成员在派生类中的访问属性分别是()。
字符串“a+b=12\n\t”的长度为()。
下列存储类标识符中,可见性与存在性不一致的是()。
若有定义“intx=4,y=5;”,则表达式“y>x++?x一一:y++”.的值为()。
在E-R图中,用来表示实体联系的图形是( )。
随机试题
辅佐抗原提高免疫原性或改变引起免疫应答类型的物质称为
下列关于营业税计税依据基本规定的表述中,错误的是()。
张教授:谁也不知道超级病毒究竟是怎样传人欧洲的,但它对欧洲人口稠密地区经济发展的负面影响是巨大的。如果这种病毒在今年继续传播蔓延,那么,国民经济的巨大损失将是无可挽回的。李教授:所以要想挽回这种损失,只要阻止这种病毒的传播就可以了。以下哪一项陈述与张教授的
近几十年来,多个职能部门和研究机构发布过的促进和保障青少年健康的调查报告和各种建议、要求已经数不胜数。关于青少年的健康状况,具体数字_________________,但是,我国青少年健康状况_________________,一些重要指标趋向负面,则是共
(0.1376,0.3651)
设f(x,y)=则f(x,y)在(0,0)处().
数据独立性是指
按照需要可以将报表以【】方式命名保存在数据库中。
PoliceinthepopularresortcityVirginiaBeachrecentlybeganoperatingvideosurveillancecameraswithcontroversialfacerec
AsanAlaskanfisherman,TimothyJune,54,usedtothinkthathewassafefromindustrialpollutants(污染物)athishomeinHaines—
最新回复
(
0
)