首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostrearn> using namespace std; class GA{ public; virtual int f(){return 1;} }; class GB:public GA{ publiC; virt
有如下程序: #include<iostrearn> using namespace std; class GA{ public; virtual int f(){return 1;} }; class GB:public GA{ publiC; virt
admin
2018-12-04
24
问题
有如下程序:
#include<iostrearn>
using namespace std;
class GA{
public;
virtual int f(){return 1;}
};
class GB:public GA{
publiC;
virtual int f(){return 2;}
};
void show(GA g){cout<<g.f();}
void display(GA &g){cout<<g.f();}
int main(){
GA a:show(a);display(a);
GB b:show(b);display(b);
return 0;
}
运行时的输出结果是( )。
选项
A、1111
B、1211
C、1112
D、1212
答案
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://jikaoti.com/ti/O2t0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列工具中为需求分析常用工具的是()。
在关系数据库中,用来表示实体之间联系的是______。
下面程序段的正确输出是intw=4,x=3,y=2,z=1;cout<<(w<x?w:z<y?z:x)<<end1;
下面不正确的描述为
下列程序的执行结果为______。#include<iostream.h>voidmain(){cout.fill(‘*’);tout.width(10);cout<<“hello”<<endl;)
已知枚举类型定义语句为:enumToken{NAME,NUMBER,PLUS=5,MINUS,PRINT=10};则下列叙述中错误的是()。
有如下程序:#inClude<iostream>usingnamespacestd;ClassTestClass{public:virtUalvoidfurll(){cout<<“funlTestc
有如下数组声明:intnumC[10],下标值引用错误的是()。
将以下程序写成三日运算表达式是_____。if(a>b)max=a;elsemax=b;
随机试题
在PCR(聚合酶链反应)中不需要的是
采用垫层法加固厚度较大的软弱地基,其最主要的作用是()。
根据《中华人民共和国进出境动植物检疫法》及其实施条例的规定,不论输往国家是否有特殊要求,出境货物的木质包装及动植物性铺垫材料均须依照规定实施检疫。()
下列关于普通股和优先股的说法中,正确的有()。Ⅰ.普通股票是最基本、最常见的一种股票Ⅱ.与优先股票相比,普通股票是标准的股票Ⅲ.与优先股票相比,普通股票是风险较小的股票Ⅳ.优先股票是一种特殊股票
某永久性投资项目初始投资额为30万元,从第一年起,每年年末可产生净收益5万元,假设基准收益率为10%,则项目的净现值为()万元。
教师职业道德与其他职业道德相同的是()
检察院开通监督电话,网站访问率很高,电话被打爆,谈谈你的看法。
据报道,上海迪士尼乐园于2016年6月16日正式开门迎客,迪士尼开园后每年将带来千亿以上旅游消费增量,这说明:
从理论上说,如果不考虑其他因素,“体型大”和“寿命长”是动物容易罹患癌症最合理的两个答案。因为“体型大”意味着组成身体的细胞数量更多,而“寿命长”意味着需要更多的新生细胞来更新换代;细胞越多,细胞分裂随机突变的几率就越高。 以下各项如果为真,最能质疑上
价格发现功能是指在一个公平、公开、高效、竞争的期货市场中,通过()的方式形成期货价格的功能。
最新回复
(
0
)