首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-09-05
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
答案
D
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行基类的Type函数,输出Animal,然后输出speak,然后执行派生类的Speak函数输出Woof,最后输出-,同理cat输出类似,所以结果为D选项正确。
转载请注明原文地址:https://www.kaotiyun.com/show/Yb5p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#include<iostream>usingnamespacestd;classAA{intn;public:AA(intk):n(k){}intget(){returnn;}intget()const{ret
下列数据结构中,能够按照“先进后出”原则存取数据的是()。
下列关于构造函数的描述中,错误的是()。
在数据库系统中,用户所见的数据模式为
下列关于二叉树的叙述中,正确的是
下面不能作为结构化方法软件需求分析工具的是()。
数据流图中带有箭头的线段表示的是()。
已知表达式++a中的“++"是作为成员函数重载的运算符,则与++a等效的运算符函数调用形式为()。
按照软件测试的一般步骤,集成测试应排列在()之后。
下面不属于软件测试实施步骤的是
随机试题
下列药物禁用于ITP病人的是
张某是某国有独资公司的董事长,下列有关说法正确的是:
关于出售公有住房引起的划拨国有土地使用权变更登记的权属审核,下列叙述正确的是()。
()能力是指在自然生态环境不受危害并维系良好生态系统的前提下,特定区域的资源禀赋和环境容量所能承载的经济规模和人口规模。
若系乘飞机离境的旅游团,地陪应提醒或协助领队提前几个小时确认机票。()
根据耶克斯一多德森定律,以下做法正确的是()。
简述故意伤害(致死)罪与过失致人死亡罪的区别。
Ifyouweretobeginanewjobtomorrow,youwouldbringwithyousomebasicstrengthsandweaknesses.Successor【C1】______inyo
Onthefirstdayofschooloneofmyclassmatesbeganatalkwithmethatchangedmylife.Shesaid,"Hi,handsome.MynameisR
A、HowtoMakeViolins.B、ExpensiveViolins.C、Stradivarius’sSecret.D、ItalianViolinMakers.C主旨题,文章提到Stradivarius小提琴非常独特,并指出S
最新回复
(
0
)