首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-07-22
58
问题
有如下程序:
#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/35Np777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
如下程序声明了一个电话号码类PhoneNumber,重载了流插入运算符<<,以便于电话号码的输出。请将程序补充完整。#include<iostream>#include<iomanip>#include<string>
有如下程序:#include<iostream>usingnamespacestdclassBase{intb;public:Base(inti){b=i;}Voiddisp(
数据流图中带有箭头的线段表示的是( )。
通过派生类的对象可直接访问其
软件结构是以【】为基础而组成的一种控制层次结构。
cin是()的一个对象,处理标准输入。
当数据的物理结构(存储结构、存取方式等)改变时,不影响数据库的逻辑结构,从而不致引起应用程序的变化,这是指数据的【】。
耦合和内聚是评价模块独立性的两个主要标准,其中【】反映了模块内务成分之间的联系。
如果一个模板声明时有类型形参表,则多个参数之间必须使用______隔开,每个参数都必须重复使用关键字______。
下列有关数据库的描述,正确的是
随机试题
企业战略专家波特认为,企业战略的核心问题应在()中考虑。
(2019年菏泽鄄城)简述影响问题解决的因素。
《菩萨蛮》(小山重叠金明灭)描写的主人公是一位()
肺心病患者肺动脉高压的主要原因是
甲开发公司(以下简甲公司)2003年3月拟在某地投资建设一处用地规模999000m2的综合小区,该地块原有133200m2工业生产用地、399600m2仓储用地、266400m2居住用地,均为国有划拨性质,其余为郊区某村办养牛场只宜种植牧草的盐碱地。甲公司
万达花园小区于2010年11月21日召开了第一次业主大会,决定选聘浩达物业服务公司进行物业管理。根据上述资料,回答下列问题。浩达物业服务公司拟确定物业服务收费,应遵循的原则有()。
与多年来国家采取的行政管房方式相比较,物业管理的一个特征就是业主与物业管理企业依法建立了(),双方依据合同享有权利并履行义务。
《物业管理条例》的立法宗旨不包括()。
小学英语新课程教学内容语言技能共分为两个级别,其中一级目标包括______、______、玩演、读写和______等五个技能。
ExteriorPaintingGettingStartedPaintingtheexteriorofyourhouseisahugejob.Buttherewardsaregreattoo.Witham
最新回复
(
0
)