首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-06-29
45
问题
有如下程序:
#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全国计算机二级
相关试题推荐
关于动态联编的下列叙述中,______是错误的。
有如下程序:#include<iostream>usingnamespacestd;classA{public:A(){cout<<“A”;}~A(){cout<<“A”;)};classB
下列关于类成员对象构造函数调用顺序的叙述中,正确的是()。
下列特征中不是面向对象方法的主要特征的是()。
若要对Data类中重载的加法运算符成员函数进行声明,下列选项中正确的是()。
数据库设计过程不包括
设循环队列为Q(1:m),其初始状态为front=rear=m。经过一系列入队与退队运算后,front=30,rear=10。现要在该循环队列中作顺序查找,最坏情况下需要比较的次数为
线性表的链式存储结构与顺序存储结构相比,链式存储结构的优点有
下列选项中,正确的C++表达式是
随机试题
可用于永久性交通标志的反光膜类型为()。
与下肢静脉检查方法和注意事项无关的是()
L一O嵌体蜡型制作中,肯定无蜡覆盖的部位是
通常情况下,由于各种进度计划编制所需要的必要资料是在项目进展过程中渐渐形成的。它的建立和完善也有一个过程。因此一个建设项目进度计划系统是( )形成的。
下列古诗与节日对应不正确的是()。
InternetdatashowsthatAmericanyoungeradultshavebecometheprimarygroupmadaboutalteringtheirpersonalappearance.Onc
•Readthetextbelowabouthowtoformagoodmanager.•Inmustofthelines41—52thereisoneextraword.Itiseithergrammat
Accordingtothespeaker,______isthemostimportantenvironmentalissuesofthemoment.Tomakesomechanges,______isacr
Themoredefinitionsagivennounhas,themorevaluableiseachone.Multipledefinitions,eachsubtlydifferentfromalltheo
他喜欢这些聚会,喜欢与年轻人交往并就各种问题交换意见。(rubShoulderswith)
最新回复
(
0
)