首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-07-22
51
问题
有如下程序:
#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
答案
C
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行基类的Type函数,输出Animal,然后输出speak,然后执行基类的Speak函数输出Voice,最后输出-,同理cat输出类似,所以结果为C选项正确。
转载请注明原文地址:https://kaotiyun.com/show/x8Np777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序:#include<fstream>#include<string>usingnamespacestd;intmain(){charch[]="Theend";
有如下程序#include<iostream>usingnameSpacestd;classbase{public:vinualvoidf1(){cout<<"F1Ba
已知二叉树后序遍历序列是dabec,中序遍历序列是debac,它的前序遍历序列是
下面是复数类complex的定义,其中作为友元函数重载的运算符“--”的功能是将参数对象的实部减1,然后返回对该对象的引用:请补充完整。classcomplex{private:intreal;int
下面程序的输出结果是【】。#include<iostream>usingnamespacestd;intx;voidfunA(int&,int);voidfunB(int,int&);intm
一般来说,数据库的设计过程要经历3个大的阶段,即可行性分析与研究阶段、系统设计阶段、设计实施与系统运行阶段。概念设计、逻辑结构设计、物理结构设计属于数据库设计的【】阶段。
按照“后进先出”原则组织数据的数据结构是
有如下类定义: class Point{ private: static int how_many; }; ______how_many=0; 要初始化Point类的静态成员how_many,下划线处应填入的内容是
当数据的物理结构(存储结构、存取方式等)改变时,不影响数据库的逻辑结构,从而不致引起应用程序的变化,这是指数据的【】。
长度为n的顺序存储线性表中,当在任何位置上插入一个元素概率都相等时,插入一个元素所需移动元素的平均个数为【】。
随机试题
AtamusicfestivalinCaliforniainJune1967,amiddle-agedsitarplayerwatchedJimiHendrixsethisguitaronfire.Thecrow
电流流过导体时使导体发热的现象称为()。
患者男,56岁。左下后牙自发性搏动疼痛4天,口含冰块可暂时缓解。检查:左下7远中可探及龋洞,叩诊不适,探诊敏感,龈缘红肿,探诊出血;左下8近中低位阻生,远中龈瓣形成盲袋,龈瓣红肿,食物嵌塞。X线片显示左下7远中龋坏,左下8近中低位阻生,无明显龋坏。对诊
根据《中华人民共和国行政处罚法》,行政机关作出行政处罚决定之前,应当告知当事人有权利要求举行听证的行政处罚包括
某市对其沿江流域进行全面规划,划分出会展区、商务区和风景区等区段进行分段设计招标,其中会展区用地100000m2,专家组综合各界意见确定了会展区的主要评价指标为:总体规划的适用性(F1)、各功能区的合理布局(F2)、与流域景观的协调一致性(F3)、充分利用
施工安全管理目标中的“一创建”是指创建()。
国际空运货物的计费重量以()为最小单位。
下里巴人:通俗
求微分方程y’-2xy=的满足初始条件y(0)=1的特解.
Someofthemostremarkablebeetlesarethedungbeetles,whichspendalmosttheirwholeliveseatingandbreedingindung1.Mor
最新回复
(
0
)