首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-09-05
43
问题
有如下程序:
#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/q4fp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
结构化程序设计的基本原则不包括
语句int*p=&k;定义了指针p,与这个语句等效的语句序列是()。
有如下程序段:inti=5;while(inti=0){cout<<’*’;i--;}运行时输出“*”的个数是()。
下i面程序输出的结果为()。#include<iostream.h>voidfun(inta,intb){inttemp;temp=a;a=b;b=temp;}
有如下类定义:classXX{intxdata;public:XX(intn=0):xdata(n){}};classYY:publicXX{intydata;p
在C++中,编译系统自动为一个类生成缺省构造函数的条件是()。
下面叙述错误的是()。
Sample是一个类,执行下面语句后,调用Sample类的构造函数的次数是()。Samplea[2],*P=newSample;
在公有继承的情况下,允许派生类直接访问的基类成员包括()。
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明IntSet是一个用于表示正整数集合的类。IntSet的成员函数Intersection的功能是求当前集合与另一个集合的交集。请完成成员函数Intersection。在mai
随机试题
杵状指的发生机制与临床意义?
IoncewenttoatowninthenorthofEnglandonbusiness.Itwasabout7:30intheeveningwhenIreachedthehotel.Them
A.酪氨酸酶缺乏B.6-磷酸葡萄糖脱氢酶分子缺陷C.苯丙氨酸羟化酶缺乏D.胆碱酯酶不可逆性抑制E.巯基酶不可逆性抑制白化病
下列关于断层的叙述不正确的是()。
求助者中心疗法所使用的“经验”的概念的含义是()。
简述中学历史教师如何提高自己的讲授能力。
下列公文属于上行文的是()。
法律不是从来就有的,是随着私有制、阶级和国家的出现而逐步产生的,只有透过各种法律现象,把握深藏其后的本质,才能深刻揭示法律的一般含义。关于法律,下列说法正确的是()
结构化程序设计的基本原则不包括
Whyrosesareredandvioletsareblue?Didyoueverwonderwhyyouseethecolorsyoudoorifotheranimalsseethesameco
最新回复
(
0
)