首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-06-10
28
问题
有如下程序:
#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/Gwfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
使用VC6打开考生文件夹下的源程序文件modil.epp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为:1063022注意:错误的语句在//*****error******的下面,修改该语句即可。#includecla
请使用“答题”菜单或使用VC6打开考生文件夹projl下的工程projl,此工程包含程序文件main.cpp,其中有类TimesTable(“乘法口诀表”)的定义和主函数main的定义。程序中位于每个//ERROR**********found*****
在C++中,用来取代C中的预处理宏函数的是
有如下程序:#includeusingnamespacestd;classPart{public:Part(intx=0):val(x){cout
下列关于函数的叙述中,正确的是
在下列关键字中,不能用来表示继承方式的是()。
在满足实体完整性约束的条件下( )。
已知i=5,j=0,下列各式中运算结果为j=6的表达式是()。
随机试题
下列不属于培训需求分析方法的是
女性,24岁,在春季旅游中途感胸闷,呼吸困难,全身大汗。查体:唇稍发绀,呼吸急促,双肺满布干啰音,心率90次/分,律齐。过去曾有类似发作,休息后自行缓解。用下列哪种药物治疗最合适
为保持MRI设备正常工作,通常MRI机房相对湿度应控制在
一小儿在接种完百白破疫苗后,局部出现红肿,直径为1.5cm,该表现属于
根据计时观察资料,测得工人工作时间如下表所示,则其工序作业时间与规范时间分别为()min。
某人在为单位采购计算机耗材时,供货商提出如果适当提高批发采购的价格,供货商可以给采购人员一定的回扣。面对供货商的条件,采购人员应该采取的态度是()。
对外贸易地理方向:指一个国家或地区进口商品的来源和出口商品的去向,从而反映该国与其他国家或地区之间的经济贸易联系程度。下列属于对外贸易地理方向的是()。
Youaretostayatthehotelwhererooms____________foryou.
John:Mary,I’mlookingforsomething【K1】______(interest)toread.Anysuggestions?Mary:Icanrecommend(推荐)AllJoyandNoFun
Specializationcanbeseenasaresponsetotheproblemofanincreasingaccumulationofscientificknowledge.Bysplittingupth
最新回复
(
0
)