首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-05-14
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、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://kaotiyun.com/show/mq8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:classXX{protected:intk;public:XX(int=5):k(n){};~XX(){tout
如果表达式y*x++中,“*”是作为成员函数重载的运算符,“++”是作为友元函数重载的运算符,采用运算符函数调用格式,该表达式还可表示为
以下内容不属于算法程序所占的存储空间的是()。
下面程序应能对两个整型变量的值进行交换。以下正确的说法是 #include<iostream.h> voidswap(intp,intq) {intt; t=p; p=q; q=t;} voidmain()
对于下面的程序:ifstreamfin(c:\test.txt);if(fin)cout<<"ok";elsecout<<"wrong";if语句中的内容可以换为
如果表达式x=y*z中的“*”是作为成员函数重的运算符,采用运算符函数调用格式,该表达式还可以表示为______。
下面关于C++语言变量的叙述错误的是
以下有关成员函数特征的叙述不正确的是
下列有关继承和派生的叙述中,正确的是()。
下列关于队列的叙述中正确的是
随机试题
贪污贿赂罪的构成要件一般有()。
动脉血压在80~180mmHg范围内波动时,肾血流量能保持不变,这是由于()
Increasinglyoverthepasttenyears,people—especiallyyoungpeople—havebecomeawareoftheneedtochangetheireatinghabits
中医诊断为治宜
当下游管道管径等于上游管道管径时,应采用()。
下列不属于设备工程实施阶段进度管理的主要任务的足( )。
背景材料: 某高速公路项目,全长45.5km,设计车速为120km/h。路面面层采用C30钢纤维水泥混凝土。该项目施工单位对面层的施工过程如下: 第一步,该施工单位按要求进行水泥混凝土配合比设计,采用实验室确定的“实验室配合比”直接配料; 第二
下列化学实验仪器名称的书写正确的是()。
中国传统文化中,雅称“岁寒三友”的是()。
下列有关执法与守法区别的说法哪些是不正确的?()
最新回复
(
0
)