首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-09-05
32
问题
有如下程序:
#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全国计算机二级
相关试题推荐
当使用ifstream流类定义一个流对象并打开一个磁盘文件时,文件的默认打开方式为()。
有如下程序:#include<iostream>usingnarnespacestd;classTestClass{public:TestClass(){cout<<’’BB’’;fun();}voidfun(){t
已知表达式++a中的“++”是作为成员函数重载的运算符,则与++a等效的运算符函数调用形式为()。
有如下程序:#include<iostream>Usingnamespacestd;classA{public:A(inti):r1(i){}vgidprint(){cout<<’
有如下程序:#includeusingnamespacestd;classBase{public:Base(intx=0){cout<<x;)};classDerived:pu
一棵二叉树中共有70个叶子结点与80个度为1的结点,则该二叉树中的总结点数为()。
下列运算符函数中,肯定不属于类Value的成员函数的是()。
若有定义“intx=4,y=5;”,则表达式“y>x++?x一一:y++”.的值为()。
下列关于算法的描述中错误的是
算法的空间复杂度是指( )。
随机试题
简要回答短销售渠道优于长销售渠道的原因。
牙齿的萌出是指A.牙齿出龈B.牙胚突破牙囊C.牙冠出龈及到达咬合的过程D.牙齿咬合E.牙胚形成到牙冠出龈
A、西咪替丁B、尼扎替丁C、法莫替丁D、雷尼替丁E、罗沙替丁乙酸酯口服吸收迅速但不完全,口服生物利用度约50%,且不受食物影响的是()。
《处方管理办法(试行)》规定,医师处方和药学专业技术人员调剂处方应当遵循的原则是()
“会计电算化”一词始于()。
下列关于物权基本原则的表述中,不符合法律规定的是()。
根据我国宪法的规定,下列属于国务院依法行使职权的是()。
社会形态是()
Whatkindsofpeopleoftengivedrugstotheirchildren?Whereintheworlddopeopledragbeforegoingtowork?Theanswersare
Whenitcomestotheslowingeconomy,EllenSperoisn’tbitinghernailsjustyet.Butthe47-year-oldmanicuristisn’tcutting,
最新回复
(
0
)