首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下列程序的输出结果为2,请将程序补充完整。 #inelude<iostream.h> using namespace std; class Base { public: ______ void fun( ){cout<<
下列程序的输出结果为2,请将程序补充完整。 #inelude<iostream.h> using namespace std; class Base { public: ______ void fun( ){cout<<
admin
2013-05-30
20
问题
下列程序的输出结果为2,请将程序补充完整。
#inelude<iostream.h>
using namespace std;
class Base
{
public:
______ void fun( ){cout<<1;}
};
class Derived: public Base
{
pbulic:
void fubn( ){cout<<2;}
};
int main( )
{Base*P=new Derived;
P→fun( );
delete P;
return 0;
}
选项
答案
virtual
解析
本题考查虚函数的概念。在C++中,一个基类的指针可以用于指向它的派生类对象。而且通过这样的指针调用虚函数时,被调用的是该指针实际指向的对象类的那个重定义版本。在本题中,通过对象指针P调用的是派生类中重定的。fun函数,那么基类中的fun只有是虚函数才能满足要求。
转载请注明原文地址:https://kaotiyun.com/show/xUNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
结构化程序设计的主要特征是()。
以下程序段的输出结果是______。inti;intx[3][3]={1,2,3,4,5,6,7,8,9};for(i=0;i<3;i++)cout<<x[i][2-i]<<‘’;
在执行下面的程序段后,a的值是为______。inta,,b;for(b=1,a=1;b<=50:b++){if(a>=10)break;if(a%2==1){a+=5;
有以下程序,程序运行的结果是______。#include<iostream.h>#include<string.h>voidmain(){charx[]="C++",y[10]="C++";
下面程序的输出结果是【】。#defineMIN(a,b)(((a)<(b))?a:b)#include<iostream.h>voidmain(){intx=3,y=5;cout<<MIN(x,y)<<end1;}
随机试题
企业竞争战略要解决的核心问题是,如何通过确定顾客需求、竞争者产品及本企业产品这三者之间的关系,来奠定本企业产品在市场上的特定地位并维持这一地位。()
甲被指控和他人一同犯有抢劫罪,开庭时,本案的其他被告人都委托了辩护人,只有甲因家境贫困没有委托辩护人,据此法院为其指定了辩护人乙,但指定后甲表示乙年老体衰,不能够有效的帮助自己辩护,主张自行辩护,则本案应当如何处理?()
[2014年,第62题]图5.3-12示冲床在钢板上冲一圆孔,圆孔的最大直径d=100mm,钢板的厚度t=10mm,钢板的剪切强度极限τb=300MPa。需要的冲压力F是()。
矿业工程锚杆安装质量的检测内容一般包括()。
张某在甲施工公司连续工作满8年;王某与乙监理公司已连续订立2次固定期限劳动合同,但因公负伤不能从事原工作;李某到丙公司工作2年,并被董事会任命为总经理;赵某在丁公司累计工作了20年,但期间曾离开过丁公司,则应当订立无固定期限劳动合同的是()。
根据《指导外商投资方向规定》的规定,外商投资企业的投资项目分为鼓励、允许、限制和禁止四类。禁止类外商投资项目是()。
按照保险对象的不同可将保险分为()。
19世纪60——90年代的洋务运动是中国逐渐汇人到工业文明大潮中的重要事件。洋务运动中,洋务派兴办同文馆等新式学堂,对中国历史发展起到的主要作用是()。
Weareonthevergeofdestroyingourozonelayer.Weareclosetodestroyinghundredsofexquisiteanimalspecies.Moreover,we
Bettingagainstanindustrywithaddictsforcustomerscarriesobviousrisks.【C1】______theseareuncertaintimesforBigTobacco
最新回复
(
0
)