首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2019-05-22
25
问题
有如下程序:
#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://jikaoti.com/ti/TXA0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
10.10此题考查的是引用的定义和使用。题目中r初始化为对x的引用,那么r的值就与x的值相等。
A、 B、 C、 D、 A本段程序实现从键盘接收一段字符串,并计算字符串的长度,cin输入流对象会将空白符、回车符、tab键作为终止标志,所以输入Ahcdefgabcd得到的字符串长度为7。
A、 B、 C、 D、 C类指针可以指向派生类对象,但是只能访问基类的数据成员和成员函数。f()作为虚函数,在派生类中被重新定义,可以通过基类指针或者引用来访问基类和派生类中的同名函数。
ABBA此题考查的是类的构造与析构。建立类的对象时,构造函数的执行顺序如下:执行基类的构造函数,调用顺序按照各个基类被继承时声明的顺序(自左向右)->执行成员对象的构造函数,调用顺序按照各个成员对象在类中声明的顺序->执行自身的构造函数。析构顺序与之相反。
内聚性衡量软件的独立性使用耦合性和内聚性两个定性的度量标准。内聚性是一个模块内部各个元素间彼此结合的紧密程度的度量,内聚是从功能角度来度量模块内的联系。耦合性是模块间互相连接的紧密程度的度量。
A、 B、 C、 D、 B建立E_R模型是数据库概念设计的重要内容,而概念设计是设计阶段的组成部分。
有如下程序:#include<iostream>usingnamespacestd;intmain(){charstr[100],*P;cout<<"pleaseinputastring:
常见的软件开发方法有结构化方法和面向对象方法。对某应用系统经过需求分析建立数据流图(DFD),则应采用______方法。
数据字典是数据库设计需求分析阶段的重要工具之一,其最基本的方法是()。
A、 B、 C、 D、 Dc++语言中析构函数为符号“~”加类名,且析构函数没有返回值和参数,故前不加void关键字。所以正确的形式应该是~Myclass()。
随机试题
人际关系对行政组织的影响。
Sometimeswinterstormsareaccompaniedbystrongwindscreatingblizzard(暴风雪)conditionswithblindingwind-drivensnow,sever
某疟疾患者发热、畏寒、寒战,体温达39℃,这主要是由于
通过土地使用权出让方式取得有限期的土地使用权。应支付()。
在个人商用房贷款合作机构风险的防控措施中,加强对合作项目审查的主要内容包括()。
价格监测的特征是()。
A.条件(1)充分,但条件(2)不充分B.条件(2)充分,但条件(1)不充分C.条件(1)和条件(2)单独都不充分,但条件(1)和条件(2)联合起来充分D.条件(1)充分,条件(2)也充分E.条件(1)和条件(2)单独都不充分,条件(1)和条件(2
请根据以下各小题的要求设计VisualBasic应用程序(包括界面和代码)。在名称为Form1的窗体上画两个名称分别为Label1、Label2,标题分别为“开始位置”、“选中字符数”的标签;画三个文本框,名称分别为txtlnput、txtBegin
Thefieldofmedicinehasalwaysattracteditsshareofquacksandcharlatans—disrepu-tablewomenandmenwithlittleornome
Acureforcancerisboundoneofthesedays.
最新回复
(
0
)