首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class GA{ public; virtual int f0{retum l;} ); class GB:public G
有如下程序: #include using namespace std; class GA{ public; virtual int f0{retum l;} ); class GB:public G
admin
2019-02-22
28
问题
有如下程序:
#include
using namespace std;
class GA{
public;
virtual int f0{retum l;}
);
class GB:public GA{
public;
virtual int f0{retum 2;}
};
void show(GA g){cout<
void display(GA&g){cout<
int main(){
GA a:show(a);display(a);
GB b:show(b);display(b);
retum O:
)
运行时的输出结果是( )。
选项
A、11 11
B、121 1
C、11 12
D、12 12
答案
C
解析
此题考查派生类与虚函数的考查。由主函数main入手,其中分别定义了类GA和GB的对象a和b。首先,执行参数a的show函数调用,其中的输出语句为调用GA类中的f()虚函数,返回1。同理display(a)函数输出1。show(b)函数中调用的为GA中的f()函数,display(b)调用GA中f()函数,返回1,display(b)调用GB中的f()函数返回2。所以最后输出为1112。
转载请注明原文地址:https://kaotiyun.com/show/GcAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序中下画线处应填入的语句是classBase{public:voidfun(){cout<<"Baseoffun"<<endl;}};classDerived:publ
若已定义:inta[]={0,1,2,3,4,5,6,7,8,9},*p=a,i;其中0≤i≤9,则对a数组元素不正确的引用是
数据库、数据库系统和数据库管理系统之间的关系是
友元函数的作用是
以下叙述中不正确的是
若已定义inta=256,执行语句cout<<hex<<a;的结果是
若有以下程序:#include<iostream>usingnamespacestd;classBase{public:Base(){x=0;}intx;};classDerived1:
程序中有如下语句:for(inti=0;i<5;i++)cout<<*(p+i)<<",";能够依次输出int型一维数组DATA的前5个元素。由此可知,变量p的定义及初始化语句是______。
在数据库系统中,用户所见的数据模式为
在下列枚举符号中,用来表示“相对于当前位置”文件定位方式的是
随机试题
下列选项中,属于阴证范畴的是()(2004年第122题)
伤寒患者灌肠时灌肠筒内液面不得高于肛门_______cm,液体量不得超过_______ml
肝胆湿热证常见的脉象是
作为指导医务人员进行医疗活动的思想和行为准则以及医疗单位目标管理重要内容的是
债券发行市场又称(),是债券发行单位向投资者发行新债券的市场。
监理单位对监理工作承担责任的原则是( )。
设f(x)在[a,b]上有定义,M>0且对任意的x,y∈[a,b],有|f(x)一f(y)|≤M|x—y|k.证明:当k>0时,f(x)在[a,b]上连续;
TheenthusiasmstemmedwiththefactwhichChina’smembershipintheWTOisalandmarkinitsopening-uppolicysincereformsbe
A、Toputanadinthenewspaper.B、Torenovatetheapartment.C、Torenttheapartment.D、Toselltheapartment.C女士说广告上说租金是每月525
Ataroundageoffive,everychildhastomakethe【C1】______fromhometoschool.Childrenatthisagehaveanenormousamountto
最新回复
(
0
)