首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2019-05-22
52
问题
有如下程序:
#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/Gb8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
函数swap(a,n)可完成对a数组从第1个元素到第n个元素两两交换。其中b[0]=1;b[1]=2;swap(b,2)。在运行调用函数中的语句后,b[0]和b[1]的值分别为()。
将:x+y*z中的“+”用成员函数重载,“*”用友元函数重载应写为()。
有如下程序:#include<iostream>usingnamespacestd;classGA{public:virtualintf(){return1;}};classGB:pu
有如下程序:#include<iostream>usingnamespacestd;classAmount{intamount;public:Amount(intn=0):amount(n){}
结构化程序设计的基本原则不包括
在软件开发中,需求分析阶段产生的主要文档是()。
A、 B、 C、 D、 C虚函数是在类的声明中使用virtual关键字来限定的成员函数,在成员函数实现时不能再使用virtual关键字进行限定。派生类中的虚函数必须和基类中的虚函数的形参个数、形参类型、返回值
A、 B、 C、 D、 C③是错误的,因为在类体内,不允许对所定义的数据成员进行初始化;其他语句构造和析构函数的定义都是正确的。
若有类声明:classMyClass{public:MyClass(){cout<<1;}};执行下列语句MyClassa,b[2],*P[2];以后,程序的输出结果是A)11
针对数组定义intdata[10];,下列叙述中错误的是A)用*data可访问到数组的首元素B)用data[9]可访问到数组的末元素C)用data[10]访问数组元素会超出数组的边界D)data共有10个元素,其首元素是data[1]
随机试题
肺热咳喘,麻黄首选配伍
根据《消费者权益保护法》及其他法律,请问,下列哪种说法不符合法律的规定?()
某机构因电液式万能试验机故障不得已将钢筋拉伸检测委托另外一家检测机构检测,这属于无能力分包。()
财政的()是指财政这种经济行为是凭借国家政治权力,通过颁布法令来实施的。
灭火器的选择应考虑()因素。
根据支付结算法律制度的规定,下列账户中,可以支取现金的有()。
微型计算机硬件系统中最核心的部件是:
著名法学家沈家本曾评论:“国不可无法,有法而不善与无法等。”下列可以代替该评论的名言是()。
下列关于栈的描述中正确的是
Mostofuswhoworkinearlychildhoodeducationfeelstronglythattheworkwedoisvaluable,【C1】______essential,tothewell
最新回复
(
0
)