首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-06-29
12
问题
有如下程序:
#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://kaotiyun.com/show/3syp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程pmjl,该工程中包含程序文件main.cpp,其中有类Door(“门”)和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正
下列运算符中,不能被重载的是
计算斐波那契数列第n项的函数定义如下:intfib(intn){if(n==0)return1;elseif(n==1)return2;e
如果派生类以protected方式继承基类,则原基类的protected成员和public成员在派生类中的访问属性分别是()。
对C++编译器区分重载函数无任何意义的信息是()。
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的CDeepCopy是一个用于表示矩阵的类。请编写这个类的赋值运算符成员函数operator=,以实现深层复制。要求:补充编制的内容写在“//**********333*
有如下类定义:classXX{intxdata;public:XX(intn=0):xdata(n){}};classYY:p
有如下类定义:classXX{intxdata;public:XX(intn=0):xdata(n){}};classYY:p
设c1和c2是类MyClass的对象,若将后缀运算符"++"作为类MyClass的友元函数重载,运算符"*"作为类MyClass的成员函数重载,则表达式c2*c1++等价于
下列关于运算符重载的描述中,正确的是()。
随机试题
肿瘤分期依据的是()。
监理工程师受业主委托实施全过程监理时,在建设工程设计准备阶段进度控制的任务有( )。
某工程的总承包人乙公司经发包人甲公司同意,将自己承包的部分建设工程分包给丙公司。因丙公司完成的工程质量出现问题,给甲公司造成200万元的经济损失。根据合同法律制度的规定,下列选项中,正确的是()。
某商场为增值税一般纳税,2001年8月发生以下购销业务:(1)购入服装两批,均取得增值税专用发票。两张专用发票上注明的货款分别为20万元和36万元,进项税额分别为3.4万元和6.12万元,其中第一批货款20万元未付,第二批货款36万元当月已付清。另外,先
“不懂体育的人,不应该当校长”是我国哪一位教育家的名言?()
义务教育的实施,使小学教育具有了()的特征。
在大时代背景下,一群文物修复师,默默地固守“冷宫”一隅,日复一日地打理着价值连城的“国宝”。宫墙外的世界______________,宫墙内的他们却要用几年的时间摩挲同一件文物。一座宫廷钟表上千个零件要______________,一件碎成100多片的青铜
设F(x)为f(x)的原函数,且当x≥0时,f(x)F(x)=,又F(0)=1,F(x)>0,求f(x).
China’sentryintotheWTOactuallyrepresentstheresultofathree-sidedwin-winsituation—China,theUnitedStatesandtheWT
TeachingandLearningManyteachersbelievethattheresponsibilitiesforlearningliewiththestudent.Ifalongreadinga
最新回复
(
0
)