首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-06-27
44
问题
有如下程序:
#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
答案
A
解析
本题考查虚函数的运用,本题中定义Dogd;Type(d)时,执行类class的Type函数,输出Dog,然后输出speak,然后执行基类的Speak函数输出Voice,最后输出-,同理cat输出类似,所以结果为A选项正确。
转载请注明原文地址:https://www.kaotiyun.com/show/KRNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序的输出结果为:Objectid=0Objectid=1请将程序补充完整。#include<iostream>usingnamespacestd;classPoint{public
下列静态数据成员的特性中,错误的是______。
以下程序的执行结果是【】。#include<iostream.h>intf(intb[],intn){inti,r=1;for(i=0;i<n;i++)r=r*b[i];retur
C++语言本身没有定义I/O操作,但I/O操作包含在C++实现中。C++标准库iostream提供了基本的I/O类。I/O操作分别由两个类istream和()提供。
若已定义的函数有返回值,则以下关于该函数调用的叙述中错误的是()。
以下运算符中不能重载的运算符是()。
在表达式x-y中,“-”是作为非成员函数重载的运算符。若使用显式的函数调用代替直接使用运算符“-”,这个表达式还可表示为()。
数据独立性是数据库技术的重要特点之一。所谓数据独立性是指
随机试题
PublicperceptionofsuccessintheU.S.mightbetotallymisguided.While92%ofpeoplebelieveotherscaremostaboutfame
A.黄连、黄柏B.黄苓、栀子C.黄连、连翘D.石膏、知母E.生地、当归(2001年第87,88题)龙胆泻肝汤与血府逐瘀汤中均含有的药物是()
化脓性关节炎最早出现的X线骨骼改变是
患者,男,40岁。症见神昏谵语,高热烦躁,痉厥抽搐,口渴唇干,尿赤,大便秘结。治宜首选
电路如图7-31(a)所示,已知R1=10Ω,R2=20Ω,uC(0一)=0,电路在t≥0暂态过程中,电容电压的变化曲线是图7-32(b)中的()。
关于高性能混凝土使用减水剂性能的要求,错误的是()。
下列符合《货物运输业小规模纳税人申请代开增值税专用发票管理办法》规定的有()。
某物业服务企业的注册资本金额为人民币200万元。则该企业的注册资金条件符合的企业管理企业资质等级为()。
领导安排你组织一次预防甲型H1N1宣传活动。你打算怎么做?
设f(x)=且f"(0)存在,求a,b,c.
最新回复
(
0
)