首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; class TestClass { int n; public: TestClass(int k):n(k)
有如下程序: #include<iostream> using namespace std; class TestClass { int n; public: TestClass(int k):n(k)
admin
2020-07-23
11
问题
有如下程序:
#include<iostream>
using namespace std;
class TestClass
{
int n;
public:
TestClass(int k):n(k){}
int get(){return n;}
im getOconst{return n+l;}
};
int main()
{
TestClass p(5);
const TestClass q(6);
cout<<p.get()<<q.get();
return 0:
}
执行后的输出结果是( )。
选项
A、55
B、57
C、75
D、77
答案
B
解析
C++中对常对象的成员函数调用,将自动调用其常成员函数,程序中调用原型为"int got()const;"的函数,对于非常对象将调用原型为"int get();’’的函数。因为首先用5对对象p进行了初始化,所以执行p.get()时直接返回5,而对于常对象则以6对q进行初始化,在调用q.get()时,将调用原型为"int got()const;"的函数,该函数将返回n+1,第二个输出应为7,所以本题答案为57。
转载请注明原文地址:https://kaotiyun.com/show/TQyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
判断一个字符串是否是回文串的递归函数定义如下:boolhuiwen(strings){intn=s.length();if(n
下列枚举类型的定义中,包含枚举值5的是
有如下类定义:classMyClass{intvalue;public:MyClass(intn):value(n){}intgetValue()const{returnvalue;}};则类MyClass的构造函数的
下列叙述中正确的是( )。
下面能作为软件需求分析工具的是
下列关于模板形参的叙述中,错误的是
支持子程序调用的数据结构是( )。
下列选项中,与实现运行时多态性无关的概念是
计算机软件包括
数据结构主要研究的是数据的逻辑结构、数据的运算和()。
随机试题
A.直肠癌B.肛瘘C.直肠息肉D.肛裂E.内痔直肠指诊可扪及索条状物可能为
红细胞渗透脆性增高,可见于
烤瓷熔附金属全冠修复体的禁忌证包括
建设项目融资方式具有多元化的特点,融资渠道呈现()。
上海以本帮菜著称的百年老店有()。
一般资料:求助者,女性,26岁,四川地震灾区某校教师。案例介绍:求助者所在学校的两座教学楼在地震中倒塌,所幸当时正是当地午休时间,师生们没在教学楼内,因此幸免于难。求助者从小胆小,这次地震使其非常恐惧,地震后不敢到房子里去,连活动板房也不敢进。无奈
一本书有160页,在它的页码中,数字“2”共出现了_________次。
A、 B、 C、 D、 B
AllSumeriancitiesrecognizedanumberofgodsincommon,includingtheskygod,thelordofstorms,andthemorningandevenin
在考生文件夹下有一个工程文件sjt3.vbp,在Forml的窗体中有一个文本框、一个计时器和两个命令按钮。程序的功能是在运行时,单击“开始计数”按钮,就开始计数(如图所示),每隔1秒,文本框中的数加l;单击“停止计数”按钮,则停止计数。要求:修改适当的控件
最新回复
(
0
)