首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-06-29
31
问题
有如下程序:
#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/zZ8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下面描述中错误的是()。A)系统总体结构图支持软件系统的详细设计B)软件设计是将软件需求转换为软件表示的过程C)数据结构与数据库设计是软件设计的任务之一D)PAD图是软件详细设计的表示工具
下列语句中不是死循环的是
流操作子______可跳过输入流中的前导空白字符。
按照标识符的要求,下列选项中,()符号不能组成标识符。
使用VC++6.0打开考生文件夹下的源程序文件2.cpp。完成空出函数fun(char*S,char*t)部分。函数fun(char*s,char*t)的功能是将在字符串S中下标为偶数位置上的字符,紧随其后重复出现一次,放在一个新串t中,t中字符按原字符
在下面的类定义中,错误的语句是()。classSample{public:Sample(intval);//①-Sample();//②private:int
使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码。补充函数convert(longS,long*str),使之从低位开始取出长整型变量S中奇数位上的数,依次存放在数str中。例如,当S中的数为:7654321时,
关于关键字class和typename,下列表述中正确的是()。
数据库设计过程不包括
随机试题
真理的价值问题是指()
施工企业为职工缴纳的失业保险费属于()。
下列金融市场中,属于货币市场的有()。
销售人员必须全面了解所销售商品的技术性能、结构、用途、用法、维修与保养等,这体现了销售人员必须掌握()。
主张教育的“生物起源说”的是()。
有三张卡片的正反面分别写着1和2,4和6,7和8,用这三张卡片组成三位数,并且6可以当9用,则可得到不同的三位数的个数为:
建造一间占地面积为12m2的背面靠墙的猪圈,底面为长方形,猪圈正面的造价为:120元/m2,侧面的造价为80元/m2,屋顶造价为1120元/m2,如果墙高3m,则最低总造价为()元。
[A]ForJacka’sstudy,67patientswithmoderateorseveredepressionwererandomlyallocatedtoeitheraMediterranean-styledi
BlogCultureThetopictodayisaboutthenewlyappearingphenomenonof(1)______.Themostsignificantrevolutionsofthel
Bythemid-19thcenturymostofEuropewasinthefirststageofthedemographictransition.Deathratehaddecreased,aswars,f
最新回复
(
0
)