首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-06-29
32
问题
有如下程序:
#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/zZ8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
软件是程序、数据和______________的集合。
派生类的成员函数不能访问基类的()。
下列数据结构中,能够按照“先进后出”原则存取数据的是
下面程序的输出结果是#include<iostream.h>classA{public:A(){cout<<"construtA"<<endl;}Virtual~A(){cout
下列关于this指针的叙述中,正确的是()。
数据结构主要研究的是数据的逻辑结构、数据的运算和()。
以下关键字用来声明类的访问权限的是
下面描述中,不属于软件危机表现的是( )。
在下列关键字中,不能用来表示继承方式的是
随机试题
机器人系统的组成不包括()
A.经典途径激活物B.旁路激活途径的固有成分C.三条激活途径的共同成分D.IFN-aE.旁路途径激活物IgG型抗原抗体复合物
预防局部麻醉药中毒哪项不正确
一消防给水系统设计工作压力为1.2MPa,该系统管网进行水压强度试验压力为()MPa。
关于优先股,以下表述错误的是()。
设某一过程的Cp=CpK=1,则它代表的合格品率为()。
企业文化的功能包括()。
下列关于法律文化的表述,正确的有()。
It’saproblemthatvexessomeofChina’sbrightestminds:whyisChinasofarbehindtheworldinmath?Afterall,thisisaco
Whyaretheagesofonetofouradangeroustimeinyoungkids’life?
最新回复
(
0
)