首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-09-05
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、DogspeakVoice-CatspeakVoice
B、DogspeakWoof-CatspeakMiaow
C、AnimalspeakVoice-AnimalspeakVoice
D、AnimalspeakWoof-AnimalspeakMiaow
答案
D
解析
本题考查虚函数的运用,本题中定义Dogd;Type(d)时,执行基类的Type函数,输出Animal,然后输出speak,然后执行派生类的Speak函数输出Woof,最后输出-,同理cat输出类似,所以结果为D选项正确。
转载请注明原文地址:https://kaotiyun.com/show/AI5p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在C++中,cin是一个()。
有如下函数模板:temp1ate<c1assT>Tsquare(Tx){returnx*x;)其中T是()。
有如下程序:#includeusingnamespacestd;classComplex{doublere,im;public:Complex(doubler,dou
下列关于运算符重载的叙述中,错误的是()。
在软件开发中,需求分析阶段可以使用的工具是()。
下列程序用来判断数组中特定元素的位置所在,则输出结果为()。#include<conio.h>#include<iostream.h>intfun(int*p,intn,int*j){inti;*j=0;for(i=0;i<n;i
下面程序中对一维坐标点类Point进行运算符重载#include<iostream>usingnamespacestd;classPoint{public:Point(intval){x=val;}
下列关于类成员对象构造函数调用顺序的叙述中,正确的是()。
有三个关系R、S和T如下:则由关系R和S得到关系T的操作是()。
某二叉树的中序序列为BDCA,后序序列为DCBA,则前序序列为
随机试题
组织文化特征中的(是指每个组织都有其组织文化,是由不同的国家和民族、不同的地域、不同的时代背景以及不同的行业特点所形成的。()
女,40岁。右上后牙自发痛、放射痛3天。半年来右上后牙冷、热刺激痛伴食物嵌塞,1个月前拔除右下智牙。检查:咬合面大面积充填体部分脱落,颊尖高陡,继发龋深,未及穿髓孔,叩诊不适,冷测引起剧烈疼痛。主诉牙的治疗方案是()
就客户利益优先的要求而言,下列关于基金从业人员应当遵守的规则的说法中,不正确的是()。
投资者A欲投资于面值100元、期限为3年、票面利率8%、年付息一次的债券,并持有到期。若A预计获得10%的到期收益率,则A购买债券时的价格约为( )元。
企业对某项投资性房地产进行改扩建等再开发且将来仍作为投资性房地产的,再开发期间应将其转入在建工程。()
图1表明儿童的发展具有()。
Alcoholmaytastesweeterifyouwereexposedtoitbeforebirth,suggestsastudyinrats.Thefindingsmayshednewlight【C1】_
有以下程序#includeintf(intx);main(){inta,b=0;for(a=0;a
NarratorListentoalectureinanartclass.Nowgetreadytoanswerthequestions.Youmayuseyournotestohelpyo
WhatdoesthewriterthinkofpeoplewhoaremakingNewYear’splans?Whenweuseourimaginationinmakingaplan______.
最新回复
(
0
)