首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-09-05
42
问题
有如下程序:
#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全国计算机二级
相关试题推荐
有如下程序:#include<iostream>voidfun(int&x,inty){intt=x;x=y;y=t;}intmain(){inta[2]={23,42};fun(a[1],a[0]);std::cout<<a[0]
对于语句cout<<end<<x;中的各个组成部分,下列叙述中错误的是()。
有如下4个语句:①tout
下列函数原型声明中,错误的是()。
下面对对象概念描述正确的是()。
在软件开发中,需求分析阶段产生的主要文档是
下面关于C++流的叙述中,正确的是()。
下列运算符函数中,肯定不属于类Value的成员函数的是()。
若MyClass是一个类名,且有如下语句序列MyClassc1,*c2;MyClass*c3=newMyClass;MyClass&c4=c1;上面的语句序列所定义的类对象的个数是()。
随机试题
压力
我国现存第一部舌诊专著是
A.速发型子孢子B.迟发型子孢子C.裂殖子D.配子体E.囊合子按蚊吸入的是疟原虫哪个阶段而继续繁殖
某生产经营单位分为东西两个区。东区有两个独立仓库,分别存放溴甲烷20t、三氧化硫50t,临界量分别是10t、75t;西区是反应区,共存放了一氯化硫3t和丙酮250t,临界量分别是1t、500t。该生产经营单位的重大危险源的个数为()。
不属于期货公司风险分类评价指标的是()。
演绎作品的作者不会因其演绎了原作品而享有被演绎作品的著作权。()
下列选项不属于合同管理中的要素构成的是()。
Itiscommonlyheldthatdrinkingmoderateamountsofalcoholcanreducetheoddsofhavingadeadlyheartattack.More(36)____
【B1】【B10】
A、Becausetheywanttoreturntothejobmarket.B、Becausetheywanttolearnsomethingnew.C、Becausetheywanttomakeupfor
最新回复
(
0
)