首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
46
问题
有如下程序:
#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全国计算机二级
相关试题推荐
下列程序的执行结果是______。#include<lostream.h>inta;intsum_a(void){a=a+5;returna;}voidmain(void)
若已定义:inta[]={0,1,2,3,4,5,6,7,8,9},*p=a,i;其中0≤i≤9,则对a数组元素不正确的引用是
已知有定义:constintD=5;inti=1;doublef=0.32;charc=15;则下列选项错误的是
下列关于C++语言类的描述中错误的是
磁盘文件操作中,打开磁盘文件的访问方式中以追加方式打开文件的
下列程序的运行结果是______。#include<iostream.h>classBase{public:voidf(intx){cout<<"Base:"<<x<<endl;}};c
______是数据库设计的核心。
数据库系统的核心的是()。
在下列关键字中,不能用来表示继承方式的是
随机试题
甲食品厂向乙面粉厂购买面粉20吨,货款共计12万元。2021年3月8日,甲食品厂向乙面粉厂出具了以自己为出票人、其开户行A银行为付款人、乙面粉厂为收款人、票面金额为12万元的见票即付的商业汇票一张,并在该汇票上签章。3月20日,乙面粉厂向丙机械厂购买一台磨
重婚罪
在借贷记账法下,所有者权益账户的期末余额等于()。
仰卧位下腹部探测输尿管与髂动脉的关系
审美意象的本质特征是___________,表现特征是___________,形象特征是荒诞性,思维特征是___________的直接参与,鉴赏特征是求解性和多义性。
在我国.宪法的修改要求全国人民代表大会()通过。
下列关于《中华苏维埃共和国婚姻法》的内容,下列表述正确的是()
ThegeologyoftheEarth’ssurfaceisdominatedbytheparticularpropertiesofwater.PresentonEarthinsolid,liquid,andga
Ourape-menforefathershadnoobviousnaturalweaponsinthestruggleforsurvivalintheopen.Theyhadneitherthepowerfult
Ifyourpurchaseisnotasdescribedorisoflowquality,youcanreturntheitemtothesellerandgetafullrefund.Conditi
最新回复
(
0
)