首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; class GA{ public; virtual int f(){return 1;} }; class
有如下程序: #include<iostream> using namespace std; class GA{ public; virtual int f(){return 1;} }; class
admin
2017-04-25
12
问题
有如下程序:
#include<iostream>
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://kaotiyun.com/show/Z2Ap777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
要定义一个引用变量p,使之引用类MyClass的一个对象,正确的定义语句是()
作为成员函数重载的运算符,第一操作数就是参数表中隐含的________所指向的对象,因此并不显示地出现在参数表中。
重载的关系运算符和逻辑运算符的返回类型应当是_______。
对于派生类的构造函数,在定义对象时构造函数的执行顺序为:先执行调用______的构造函数,再执行调用子对象类的构造函数,最后执行派生类的构造函数体中的内容。
根据下面的程序,可以在主程序中使用的合法语句是( )。 #include <iostream> using namespace std; class Person{ int age; voidtest(){}
设有如下关系表:则下列操作中正确的是
假定要访问一个结构指针p所指对象中的b指针成员所指的对象,则表示方法为【 】。
用单链表表示的链式队列的队头在链表的( )位置。
在面面对泵方法中,一个对象请求另一对象为其服务的方式是通过发送【 】实现。
以下选项中与k=n++;完全等价的表达式是
随机试题
在世界文学史上开辟了无产阶级文学新纪元的作品是【】
脐带中的脐动脉有
当某房地产投资项目的基准收益率大于银行贷款利率且该项目在经济上又是可行的,那么其资本金的内部收益就大于全投资内部收益率。()
在进行融资前分析时,估算财务效益和费用时首先应估算()。
背景材料:某公司(甲方)与某建筑公司(乙方)订立了桥梁基础施工合同,同时又与丙方订立了工程降水合同,基础施工合同约定采用综合单价承包。该基础工程施工网络计划如下图所示。甲乙双方约定某年6月15日开工,在工程施工中发生了如下事件。事件一:由于降水施工
下列情形中,国家不承担赔偿责任的是()。
选出下列文学常识表述正确的一项:
要使文件菜单顶用“F”作为访问快捷键,可用()定义该菜单标题。
下列诸因素中,对微型计算机工作影响最小的是
A.qualifiedB.conductedC.reactionsD.privatelyE.responsesF.employersG.conservativeH.presentlyI.surviveJ.pos
最新回复
(
0
)