首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2019-05-22
23
问题
有如下程序:
#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
答案
A
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行类class的Type函数,输出Dog,然后输出speak,然后执行基类的Speak函数输出Voice,最后输出-,同理cat输出类似,所以结果为A选项正确。
转载请注明原文地址:https://kaotiyun.com/show/oB8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
A、 B、 C、 D、 B快速排序的基本思想是:从表中选取一个元素(如本题中的33),将表中小于此元素的移到前面,大于此元素的移到后面,结果把线性表分割成两部分(两个子表),此元素插入到其分界线的位置处。然后
A、 B、 C、 D、 C通过调用友元函数,实现求解n!的算法。sum=5!+4!+3!+2!。
A、 B、 C、 D、 A此题考查的是类和对象的相关概念。类是将不同的数据和与这些数据相关的操作封装起来装在一起的集合体。对象是类的具体实例,也即类是对某一类对象的抽象,类和对象之间可以说是数据类型与变量的关
A、 B、 C、 D、 B栈是一种特殊的线性表,其插入和删除运算都只在线性表的一端进行,而另一端是封闭的。进行插入、删除的一端称为栈顶,封闭的一端称为栈底。栈顶元素是最后被插入的元素,而是最后被删除的,是按先
下列程序的输出结果是______。#include<iostream>#include<cstring>usingnamespacestd;voidfun(constchar*S,char&C){e=
类在面向对象方法中,把具有相同属性和方法的对象称为类,类是对象的抽象,对象是类的实例。
A、 B、 C、 D、 A由于线性表采用的是顺序存储方式,用存储单元的邻接性体现线性表元素间的一维顺序关系,因此对线性表进行插入和删除运算时,可能需要移动大量的结点,以保持这种物理和逻辑的一致性。对于选项A)
参照完整性关系模型的完整性规则是对关系的某种约束条件,它允许定义三类数据约束,分别是:实体完整性、参照完整性及自定义完整性,其中前两种完整性约束由关系数据库系统自动支持。
C++中每个类都有一个隐含的______指针。
随机试题
Topreservefood,thegrowthofbacteria(细菌)mustbecontrolled.Water,warmth,andfoodareallneededforbacteriatobecomest
A.增强润肺止咳作用B.增强补脾益气作用C.缓和药性D.长于益气补中E.滋阴降火蜜炙枇杷叶()。
在英国,测量师协会的主要功能体现为三个方面:教育和培训(EducationandTraining)、制定规划(Regulation)、代表制(Representation)。其中代表制度主要活动是()。
公盘制是房地产经纪机构共享房源信息的形式之一,有利于()。
《中华人民共和国环境保护法》规定:建设项目的环境影响报告书,必须对建设项目产生的污染和对()作出评价,规定防治措施,经项目主管部门预审并依照规定的程序报环境保护行政主管部门批准。
张先生想办一张信用卡,于是向理财规划师了解信用卡的有关功能。下列选项不属于信用卡功能的是()。
乙股份有限公司(以下简称“乙公司”)为华东地区的一家上市公司,属于增值税一般纳税人。乙公司2013年至2016年与固定资产有关的业务资料如下:(1)2013年12月1日,乙公司购入一条需要安装的生产线,取得的增值税专用发票上注明的生产线售价为1170万元
下列设备中,能够控制广播包的网络设备是(35)。
在Linux中常使用wu-ftpd构建FTP服务器,如果希望使某用户无法访问FTP服务器,应在配置文件(1)_____中进行设置,统计当前登录FTP的人数应该使用(2)____命令,通过运行(3)_____命令可以设置在操作系统启动时自动运
ConversationalSkills1.Skilltoaskquestionsa)Beawareofthehumannature:readinesstoanswerothers’questionsr
最新回复
(
0
)