首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-05-14
37
问题
有如下程序:
#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全国计算机二级
相关试题推荐
下列程序的执行结果为#include<iostream.h>voidmain(){inta=3,b=0;int*p=&a;b=+a++;cout<<
如果表达式y*x++中,“*”是作为成员函数重载的运算符,“++”是作为友元函数重载的运算符,采用运算符函数调用格式,该表达式还可表示为
函数swap(arr,n)可完成对arr数组从第1个元素到第n个元素两两交换。在运行调用函数中的语句后,a[0]和a[1]的值分别为【】。a[0]=1;a[1]=2;swap(a,2);
有如下定义:intb[10]={1,2,3,4,5,6,7,8,9,10},*q=b;则数值为8的表达式是()。
下列关于线性链表的叙述中,正确的是()。A)各数据结点的存储空间可以不连续,但它们的存储顺序与逻辑顺序必须一致B)各数据结点的存储顺序与逻辑顺序可以不一致,但它们的存储空间必须连续C)进行插入与删除时,不需要移动表中的元素D)以上三
以下有关成员函数特征的叙述不正确的是
关于动态联编的下列叙述中,______是错误的。
下列叙述中正确的是
下列有关函数重载的叙述中,错误的是
随机试题
完带汤中配伍柴胡、芥穗的意义是
A.维生素B12吸收障碍B.铜代谢异常C.铁代谢异常D.L啉代谢异常E.嘌呤代谢异常
男,50岁。持续性心房颤动6年,3年前曾出现言语不利、左侧肢体活动障碍,该患者长期抗凝治疗应首选()
A.己烯雌酚B.地高辛C.环孢素D.茶碱E.三环类抗抑郁药体内过程个体差异大的是()。
某项目建设期1年,生产期6年,长期借款3000万元,建设期年初借款,借款年利率10%,在生产期前5年等额还本利息照付,每年还本额为()万元。
商品流通企业在选择供应商时,评价供应商的供应指标包括准时交货率、交货周期和()。
Overthepastdecade,thousandsofpatentshavebeengrantedforwhatarecalledbusinessmethods.Amazon.conreceivedoneforits
主要误差来源是内容取样的信度估计方法有
______bothinworkinglifeandeverydaylivingtodifferentsetsofvalues,andexpectationsplacesaseverestrainontheindiv
IndependentWritingDirectionsForthistask,youwillwriteanessayinresponsetoaquestionthatasksyoutostate,expl
最新回复
(
0
)