首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序 #include<iostream> #include<string> using namespace std; class base { private: charbaseName[10]; public: base
有以下程序 #include<iostream> #include<string> using namespace std; class base { private: charbaseName[10]; public: base
admin
2010-03-29
88
问题
有以下程序 #include<iostream> #include<string> using namespace std; class base { private: charbaseName[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.myName0<<" "<<p.className(); } int main() { base bb; Derived dd; showPtr(dD) ; retum 0; } 动行后的输出结果为
选项
A、Derived Base
B、Base Base
C、Derived Derived
D、Base Derived
答案
1
解析
本题考核虚函数的应用。类Derived是从基类Base公有派生而来的。因此, Derived是基类Base的子类型。main()函数中定义了一个基类对象bb和一个派生类对象dd。从程序中可看出派生类Derived的对象dd交给了处理基类Base的对象的函数 showPtr进行处理。由于在基类中函数myName被定义成虚函数。所以在函数showPtr中调用的myName函数为派生类的成员函数myName,从而输出Derived。然后输出 className,即基类名称Base。
转载请注明原文地址:https://www.kaotiyun.com/show/Yhjp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序:#includestructS{inta,b;}data[2]={10,100,20,200};main(){structSP=data[1]
在数据库管理系统提供的数据语言中,负责数据的查询、增加、删除和修改等操作的是
以下叙述中正确的是
下面属于黑盒测试方法的是
以下叙述中错误的是
有三个关系R、S和T如下:则由关系R和关系S得到关系T的操作是()。
以下选项中不属于C语言程序运算符的是
设栈的顺序存储空间为S(1:m),初始状态为top=0。现经过一系列正常的入栈与退栈操作后,top=m+1,则栈中的元素个数为
下列关于逻辑运算符两侧运算对象的叙述中正确的是()。
有以下程序,其中%u表示按无符号整数输出()。main(){unsignedintx=0xFFFF;/*x的初值为十六进制数*/printf("%u\n",x);}程序运行后的输出结果是(
随机试题
作为管理者把重要的信息传递给工作小组成员是其一项重要职责,这时管理者承担的角色是()
参与围成咽峡的结构有
在下列有关抗震设防的说法中,哪些选项是符合规定的?()
自动化仪表工程连续()小时开通投入运行正常后,即具备交接验收条件。
剩余股利政策的优点在于()。
从决策的基本属性来看,决策是()。
视觉上对色彩的感觉有三个特征,其中不属于这些特征的是(33),三个特征中有两个有时通称(34)。
Withtheunderstandingofphobiashascomeamagicbagoftreatments:exposuretherapythatcanstompoutalifetimephobiaina
Listentothefollowingpassage.Altogetherthepassagewillbereadtoyoufourtimes.Duringthefirstreading,whichwillbe
Realpolicemenhardlyrecognizeanyresemblancebetweentheirlivesandwhatthey【S1】______onTV—iftheyevergethomeintime
最新回复
(
0
)