首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-05-14
46
问题
有如下程序:
#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
答案
B
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行类class的Type函数,输出Dog,然后输出speak,然后执行派生类的Speak函数输出Voice,最后输出-,同理cat输出类似,所以结果为B选项正确。
转载请注明原文地址:https://kaotiyun.com/show/mq8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
以下内容不属于算法程序所占的存储空间的是()。
请指出程序片段的语法错误______。
对于下面的程序:ifstreamfin(c:\test.txt);if(fin)cout<<"ok";elsecout<<"wrong";if语句中的内容可以换为
下面程序的输出结果是()。#include<iostream.h>#include<string.h>voidmain(){charp1[10],p2[10];strcpy(p1,”abc”);
C++在重载运算中,如用成员函数重载一元运算符参数表中需要【】个参数,如用友元函数重载一元运算符参数表中需要1个参数。
已知在函数func()中语句this->ff=0;与语句fi=O;的效果完全相同。对于这一现象,下列表述中错误的是()。
下面关于C++语言变量的叙述错误的是
以下有关成员函数特征的叙述不正确的是
对于浯句cout<<end1<<x;中的各个组成部分,下列叙述中错误的是()。
下列有关函数重载的叙述中,错误的是
随机试题
汽车行驶减小或消除汽车前进中,因前轮外倾和纵向阻力致使前轮前端向外滚开所造成的滑移的是()。
为预防结石复发,下列哪种结石需要酸化尿液
低血容量休克的体位最好是
耳部重要结构大都隐藏在颅骨内,结构细微复杂,CT扫描前应详细临床资料和检查要求。关于耳部CT扫描适应证,下列错误的是
A.0.5%的醋酸冲洗B.2%~4%的碳酸氢钠冲洗C.奥平(α-干扰素)D.复方己烯雌酚胶囊E.氯洁霉素
下列各项中,属于期间费用的有( )。
案例: 2018年6月18日,甲向乙银行借款100万元,借期一年。同时,甲以其市价100万元的挖掘机作抵押,并约定:借款到期,若甲不能偿还借款本息,挖掘机直接归乙银行所有。双方签订了书面抵押合同,但未办理抵押登记。 7月17日,甲将挖掘机出租给丙,双方
胃的“一点癌”是指
下列不重视人文学科的是
Whenmedal-winningathletesreturnhomefromtheOlympicGames,theirfamemaybeshort-lived,buttheycanlookforwardtoalo
最新回复
(
0
)