首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-05-14
39
问题
有如下程序:
#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://www.kaotiyun.com/show/mq8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序的执行结果为#include<iostream.h>voidmain(){inta=3,b=0;int*p=&a;b=+a++;cout<<
有如下程序:#include<iostream>usingnamespacestd;classCA{public:CA(){cout<<’A’;}};classCB:priva
下列程序的输出结果是______。#include<iostream>usingnamespacestd;intmain(){chara[]="Hello,World";ch
如果表达式x=y*z中的“*”是作为成员函数重的运算符,采用运算符函数调用格式,该表达式还可以表示为______。
对定义重载函数的下列要求中,()是错误的。
下列叙述中正确的是
下列关于运算符重载的叙述中,错误的是
以下有关成员函数特征的叙述不正确的是
下列关于队列的叙述中正确的是
随机试题
设计和维持一种有助于提高集体活动效果的组织结构的活动过程是()
急性化脓性骨髓炎应与下列哪些疾病鉴别
化脓性关节炎早期诊断中,最有价值的方法是
以下公式表示试算平衡关系,正确的是()。
唐代茶圣陆羽的《茶经》是中国也是世界第一部茶叶科学专著。()
在当代中国,发展先进文化,就是()。
设f(x)在区间[a,b]上可导,且满足求证:至少存在一点ξ∈(a,b)使得f(ξ)=-f’(ξ).
函数y=y(x)由方程cos(x2+y2)+ex一x2y=0所确定,求
A.daydreamB.disagreementC.factuallyD.ifE.inevitableF.inseparableG.laysH.makingI.perspectiveJ.residesK.
WhydoweinvestsomuchhopeinnewtechnologyandwhyarewesodisappointedwhentheNextBigThingturnsouttobejustane
最新回复
(
0
)