首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-07-22
22
问题
有如下程序:
#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
答案
D
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行基类的Type函数,输出Animal,然后输出speak,然后执行派生类的Speak函数输出Woof,最后输出-,同理cat输出类似,所以结果为D选项正确。
转载请注明原文地址:https://jikaoti.com/ti/aVE0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序:#include<iostream>usingnamespacestd;classComplex{public:Complex(doubler=0,doublei=0)
数据是指所有能输入到计算机之中并被计算机程序处理的()。
如果要把返回值为void的函数A声明为类B的友元函数,则应在类B的定义中加入的语句是【】。
一个类的友元函数能够访问该类的()。
有如下程序段&include<iostream.h>voidmain(){inta=14,b=15,x;charc=’A’x=(a&&b)&&(c<’B’=;
继承的方式有公有继承、私有继承和【】种。
继承的方式有公有继承、私有继承和【】3种。
相对于数据库系统,文件系统的主要缺陷有数据关联差、数据不一致性和
下述关于数据库系统的叙述中正确的是
随机试题
下列给定程序中,函数fun的功能是:找出100—999(含100和999)所有整数中各位上数字之和为X(x为正整数)的整数,并输出;符合条件的整数个数作为函数值返回。例如,当x值为5时,100—999各位上数字之和为5的整数有:104,113,1
王某在病床弥留之际立下口头遗嘱,其财产分别由其儿子和女儿继承。王某立口头遗嘱时,在场人员有儿子、女儿、医生和做护士的儿媳。依照法律规定,下列人员中,能够作为口头遗嘱见证人的是()
以下哪项不是椎管内麻醉中恶心呕吐的主要原因
患者,女,56岁。上腹不适嗳气1个月,进食如常。胃镜示:胃角小弯侧1cm×0.6cm局限性黏膜粗糙、糜烂,亚甲蓝喷洒后着色明显。下列治疗首选
甘油在软胶囊剂囊材中的作用是
机体保钠排钾的主要激素是
举之有余,按之不足的脉象为
患者,男性,48岁。2天前突然寒战、高热,胸痛、咳嗽、咳脓痰、气短。查体:精神委靡,四肢末梢凉,体温36.9℃,血压75/55mmHg,脉搏细弱,双肺下部闻及湿哕音。考虑可能是
某期货公司的资产为3亿元,负债为1.8亿元,该公司进入风险预警期。在风险预警期,证监会派出机构可以采取的措施有()。
垄断是通过一定的垄断组织形式实现的。由于在资本主义发展过程中生产社会化和生产集中的发展程度的不同,资本主义大型企业之间互相勾结或联合的程度和具体目的也不一样,因而垄断组织便有各种不同的形式。常见的垄断组织有卡特尔、辛迪加、托拉斯和康采恩等。尽管垄断组织的形
最新回复
(
0
)