首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-05-06
44
问题
有如下程序:
#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://www.kaotiyun.com/show/BWfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
静态数据成员在()进行初始化。
有下列程序:#includevoidmain(){inta1,a2charc1,c2;scanf("%d%c%d%c",&a1,&c1,&a2,&c2);printf("%d%c%d%c",a1
下列选项中,不是C++关键字的是
下列有关内联函数的叙述中,正确的是()。
下列存储类标识符中,可见性与存在性不一致的是()。
若MyClass为一个类,执行“MyClassa[4],*p[5];”语句时会自动调用该类构造函数的次数是()。
在数据库设计中,将E-R图转换成关系数据模型的过程属于()。
在C++程序中,如果要求通过函数来实现一种简单的功能,并且要求尽可能加快程序执行速度,则应该选用()。
设二叉树如下:则中序序列为
随机试题
蹲点调查
关于甲状腺功能亢进叙述不正确的是
《安全生产法》的许多条文都是围绕着从业人员的人身安全规定的,要求生产经营单位必须围绕着保障()这个核心抓好安全管理工作。
某酒厂(增值税一般纳税人)生产以粮食、薯类酒精为原料的白酒,同时也生产啤酒。2017年12月该厂的生产销售情况如下:(1)外购薯类酒精10吨,增值税专用发票上注明单价每吨1500元;外购粮食酒精20吨,增值税专用发票上注明单价每吨2100元;(2)
阅读下列材料,回答问题。我在单位工作很有成就感,因此,在日常的生活和工作中,我不怕见父母,不怕见邻居,不怕见同事和领导,但是就怕见我孩子的班主任老师。都怪我的儿子不争气,我总是挨这位老师的训。我儿子爱说爱动,在课堂上时常有“违反”纪律的现象,因此
有知名作家要来你所在的铁路派出所进行交流采风活动,为了更好地展示警营风采,做好接待。领导让你负责此次活动,你认为工作的重点是什么?
A、 B、 C、 D、 D
有以下程序:main(){intx[]={1,3,5,7,2,4,6,0},i,j,k;for(i=0;i<3;i++)for(j=2;j>=i;j--)if(x[j+1)>x[j]
TheProblemsLearnersofEnglishFaceTheproblemslearnersofEnglishfacecanbedividedintothreebroadcategories:a)
PolitebehaviorisimportantintheAustraliansociety."Please"and"thankyou"arewordswhichareveryhelpfulwhen【C1】_____
最新回复
(
0
)