首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; int i=1; class Fun { public: static int i; int va
有如下程序: #include<iostream> using namespace std; int i=1; class Fun { public: static int i; int va
admin
2020-04-07
68
问题
有如下程序:
#include<iostream>
using namespace std;
int i=1;
class Fun
{
public:
static int i;
int value(){return i-1;}
int value()const{return i+1;}
};
int Fun::i=2;
int main()
{
int i=3;
Fun fun1;
const Fun fun2;
_______
return 0:
}
若程序的输出结果是:123
则程序中横线处的语句是( )。
选项
A、cout<<fun1.value()<<Fun:i<<fun2.value();
B、cout<<Fun::i<<fun1.value()<<fun2.value();
C、cout<<fun1.value()<<fun2.value()<<Fun::i;
D、cout<<fun2.value()<<Fun::i<<fun1.value();
答案
A
解析
此题因为定义的变量i是static类型的(main()函数内部的i只是一个局部变量),所以,选项A中fun1.value()的返回值是1,Fun::i引用的是外部变量会输出2;fun2.value();会调用常成员函数int value()const{return i+l;}使得外部静态变量i的值增加为3,故输出3。
转载请注明原文地址:https://kaotiyun.com/show/9N8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在面向对象方法中,类的实例称为【 】。
下列类的构造函数不能通过编译,正确的构造函数应该是【 】。#inelude<iostream.h>classSample{public:intnsconstintcon,Sample(intm){con=
Staff类含有int型数据成员ID,两个Staff对象相等是指它们的ID相同。下面的函数重载了运算符==,它用来判断两个Staff对象是否相等,相等时返回true,否则返回false。请将横线处缺失部分补充完整。boolStaff::Staf
请在下列程序中的横线处填写正确的语句。#include<iostream>usingnamespacestd;classBase{public:voidfun(){cout<<"Basefun"<<
下列选项中不符合良好程序设计风格的是()。
()使一个函数可以定义成对许多不同数据类型完成同一个任务。
两个或两个以上模块之间联系的紧密程度称为()。
下列程序中画线处应填入的语句是classBase{public:voidfun(){cout<<"Baseoffun"<<end1;}};
下列对变量的引用中,错误的是
下述关于数据库系统的叙述中正确的是
随机试题
有效提高会议质量的措施有哪些?
下列疾病中,较少合并缺铁性贫血的是
下列关于中草药的保管方法正确的是
企业在客户取得相关商品控制权时确认收入,下列各情形中,属于客户取得商品控制权的有()。
我国人民代表大会制度的核心内容和实质是()。
f(x)在[0,1]上有连续导数,且f(0)=0,证明:存在ξ∈[0,1],使得f’(ξ)=2∫01f(x)dx.
计算∫L(3x+2y+1)dx+,其中L为x2+y2=4第一象限内逆时针方向部分.
Thoughnotbiologicallyrelated,friendsareas"related"asfourthcousins,sharingabout1%ofgenes.Thatis【B1】______astudy
Afteryou’vestarttomasterthetechniques,therealstruggleisjustbeginning.It’s______thatmakesyougreat.
Whilethenewsseemstohighlightthemountingexternalandinternalpressuresthataredrivinglanguageendangerment,notall
最新回复
(
0
)