首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序 #include <iostream> #include <string> using namespace std; class base { private: char baseName[10];
有以下程序 #include <iostream> #include <string> using namespace std; class base { private: char baseName[10];
admin
2010-06-06
22
问题
有以下程序 #include <iostream> #include <string> using namespace std; class base { private: char baseName[10]; public: base () { strcpy(baseName,"Base"); } virtual char *myName() { return baseName; } char *className() { return baseName; } }; class Derived : public base { private: char derivedName[10]; public: Derived() { strcpy(derivedName,"Derived"); } char *myName() { return derivedName; } char *className() { return derivedName; } }; void showPtr(base &p) { cout<<p.myName () <<" "<<p.className (); } int main () { base bb; Derived dd; showPtr(dd); return 0; } 运行后的输出结果为
选项
A、Derived Base
B、Base Base
C、Derived Derived
D、Base Derived
答案
A
解析
本题考核虚函数的应用。类Derived是从基类Base公有派生而来的。因此,Derived是基类Base的子类型。main()函数中定义了一个基类对象bb和一个派生类对象dd。从程序,中可看出派生类Derived的对象dd交给了处理基类Base的对象的函数showPtr进行处理。由于在基类中函数myName被定义成虚函数。所以在函数 showPtr中调用的myName函数为派生类的成员函数 myName,从而输出Derived。然后输出className,即基类名称Base。
转载请注明原文地址:https://kaotiyun.com/show/Jajp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
对长度为n的线性表排序,在最坏情况下,比较次数不是n(n-1)/2的排序方法是()。
学生记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组中,请编写函数fun,其功能是:把分数最低的学生数据放入b所指的数组中,注意:分数最低的学生可能不止一个,函数返回分数最低的学生人数。注意:部分源程序在文件PROGl.C中。请勿改动主函
下列选项中可作为C语言合法常量的是()。
软件设计中模块划分应遵循的准则是()。
在关系中凡能惟一标识元组的最小属性集称为该表的键或码。二维表中可能有若干个键,它们称为该表的()。
以下表达式中,其值不等于数值3的是()。
以下能正确表述算式sin(2πr+30°)的C语言表达式是()。
下面是一个栈类的模板,其中push函数将元素i压入栈顶,pop函数弹出栈顶元素。栈初始为空,top值为0,栈顶元素在stack[top-1]中,在下面横线处填上适当语句,完成栈类模板的定义。template<classT>classTstack
有如下函数模板定义:template<typenameT1,inta2,inta3>T1sum(T1a1){return(a1+a2+a3);}则以下调用中正确的是()。
针对数组定义intdata[10];,下列表述中错误的是______。
随机试题
环保疏浚的主要目的是()。
应激状态时不出现
在实施局部麻醉时,宜将局部麻醉药中加入少量肾上腺素以达到延长麻醉阻滞时间的患者是
在某工厂的控烟教育中,厂区开设了呖烟室,也标定了“无烟区”,这属于健康教育策略中的
A、氯霉素B、链霉素C、白喉毒素D、林可霉素E、嘌吟霉素对原核和真核生物蛋白质合成都抑制的是
根据我国有关规定,下列作业须进行特种作业人员安全资格认证的有()。
单位、个人和银行在办理支付结算时必须遵守的原则有()。
中国最早建立的佛教寺院是()。
明清时期,科举考试中哪种考试被称作春闱()
We’veallusedthermometerstomeasuretemperaturebutsometimesweneedtomeasuretemperatureinplacesyoucan’tput
最新回复
(
0
)