首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2015-06-27
54
问题
有如下程序:
#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://kaotiyun.com/show/dBBD777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
简述福特制和美国工业主义的特征。(北京大学2017年世界史真题)
根据数据的观测方法和来源划分,研究数据可以分为()
下列说法错误的是
教育要适应儿童身心发展的顺序性,应该
实体法与程序法的划分标准是()。
抗日民主政权制定的最具代表性的宪法性文件是()
元朝对科举考试方式进行改革的最突出表现是
下列关于法治国家中法律与其他社会调控方式的关系的说法中,正确的是
下列属于合法的Java标识符的是()。
交换两个变量的值,不允许用临时变量,应该使用下列()位运算符。
随机试题
存储1024个24×24点阵的汉字字形码需要的字节数是________。
StudentA:IamsorryIbrokeyourglasses.StudentB:______
颊尖略偏远中的前磨牙是
患者男,58岁。头痛,呕吐2个月余。行颅脑MRI示:右额叶占位。后行开颅探查+肿瘤切除术,病检示“胶质母细胞瘤”。该患者放射治疗设野的CTV设定为
A.麻黄B.芦荟C.白果D.何首乌E.千金子易霉变的饮片是
下列属于效力待定合同的有( )。
中国历史上废除丞相制度的皇帝是()。
求幂级数的和函数.
A、 B、 C、 D、 A
在考生文件夹下,打开文档Word1.docx,按照要求完成下列操作并以该件名Word1.docx保存文档。将标题段文字(“产品质量法实施不力地方保护仍是重大障碍”)设置为三号、楷体、蓝色(标准色)、倾斜、居中并添加黄色(标准色)底纹;将标题段设置为段后
最新回复
(
0
)