首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2019-03-05
53
问题
有如下程序:
#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
答案
A
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行类class的Type函数,输出Dog,然后输出speak,然后执行基类的Speak函数输出Voice,最后输出-,同理cat输出类似,所以结果为A选项正确。
转载请注明原文地址:https://www.kaotiyun.com/show/LqAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
已知类A有公用数据成员a,并重载了=运算符,且有Aobj2;constAptr*=newA;则下列语句错误的是
以下叙述正确的是
下面赋值语句中正确的是
下面程序的运行结果是()。#include<iostream.h>voidmain(){inti=1;while(i<=8)if(++i%3!=2)continue;elsecout<<
下列叙述中正确的是()。
下列关于C++流的叙述中,正确的是
存取指针所指的值时,采用的运算符是()。
下列数据模型中,具有坚实理论基础的是()。
假定A为一个类,则语句A(A&a);为该类______函数的原型说明。
在深度为6的满二叉树中,度为2的结点个数为______。
随机试题
Manystudentsfindtheexperienceofattendinguniversitylecturestobeaconfusingandfrustratingexperience.Thelecturersp
1级高血压伴2个危险因素的存在属于高血压危险分层中低危组。
希恩(Sheehan)综合征的主要原因是()
分配尸体器官的准则是
患者在连续硬膜外麻醉下行胆囊切除术,手术开始前测麻醉平面为T4~T12血压、脉搏正常。术中探查胆囊时患者诉恶心,血压降至86/50mmHg,心率减慢至52次/分。可能是由于
最易发生脑缺氧发作的先天性心脏病是:
工艺过程中产生的静电的最大危险是()。
跨度为12m的单层工业厂房,可采用的结构类型主要是()。
与一般身体锻炼相比,学校体育更具有()。
Inthe1800s,thereAwereabout1,000BmillionpeopleonEarth,anduntilrecently,therewasCfewincreaseinworldDpopulation
最新回复
(
0
)