首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-09-05
33
问题
有如下程序:
#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://kaotiyun.com/show/Yb5p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
已知函数f的原型是voidf(int*a,long&b);,变量vl、v2的定义是:imvl;longv2;下列调用语句中正确的是()。
在类中重载赋值运算符时,应将其声明为类的()。
下列关于基类和派生类关系的叙述中,正确的是()。
将以下程序写成三目运算表达式是()。if(x<y)min=x;elserain=y;
下面不能作为结构化方法软件需求分析工具的是()。
如需要向一个二进制文件尾部添加数据,则该文件的打开方式为()。
下列数据结构中,能够按照“先进后出”原则存取数据的是()。
如果利用C++流进行输入输出,下面的叙述中正确的是()。
下列关于二叉树的叙述中,正确的是
某二叉树有5个度为2的结点,则该二叉树中的叶子结点数是()。
随机试题
对于胞内寄生虫的免疫逃逸机制,下列哪一项错误
采用分页式存储管理时,相对地址由两部分组成:( )和( )。
某混凝土试验室配合比为水泥:水:砂:碎石=340:190:608:1215,实测施工现场砂的含水率为3%,碎石的含水率为1%,若工地搅拌机容量为0.4m3(出料),为施工方便,每次投入2袋水泥(50kg/袋),问其他各材料的投入量为多少?
在分部分项工程量清单编制时,下列项目特征中可不描述的有()。
甲企业的有关情况如下:(1)2013年1月,甲企业为支付A企业的货款,向A企业签发一张100万元的转账支票。出票日期为1月10日,付款人为乙银行。持票人A企业于1月18日到乙银行提示付款时,乙银行以出票人甲企业的存款账户资金不足100万元为由拒绝
FormaccountissuedA.usuallymadeinthe(56)______ofacheckB.Aterminationnoticeshouldbe(57)______bythepersonneldepar
•ReadthetextbelowaboutjobprospectsattheIBCBank.•ChoosethecorrectwordA,B,CorDfrombelowthepassagetofille
Whichofthefollowingcontainsacomplement?
Whatisthenewsitemmainlyabout?
A、Iusuallygofishing.B、Iamateacher.C、IcomefromAmerica.D、Yes,Ido.A应该具体回答所做的事情,故选A。
最新回复
(
0
)