首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
2019-07-10
65
问题
有如下程序:
#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://www.kaotiyun.com/show/eX8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序: #nclude<iostream> using namespace std; class MyClass{ public: MyClass(int x):val(x){} void Se
下面程序段的输出结果是______。char*s="12345";s+=2;cout<<*s;
以下不能正确进行字符串赋值初值的语句是()。
以下程序的输出结果是【】。#include<iostream.h>voidmain(){inta=0;a+=(a=8);cout<<a;
有如下类声明:classFoo{intbar;};则Foo类的成员bar是()。
随机试题
某照相馆以房屋为抵押,向银行贷款1万元,后又以该房屋为抵押向裕丰商行借款1-5万元。前项抵押未经登记,后项抵押则经过了登记。但经估计,该房屋仅值2万元。按法律规定,该房屋应由()
判断股份制企业的性质,关键是看()
全面质量管理的英文缩写为
在建设工程项目进度计划系统中,按计划的深度不同划分的进度计划包括()
Cutsinfundinghavemeantthatequipmenthasbeenkeptinservicelongafterit______replaced.
在窗体上画一个名称为Text1的文本框和一个名称为Command1的命令按钮,然后编写如下事件过程:PrivateSubCommand1_Click()DimiAsInteger,nAsIntegerFori=0T
下列选项中不属于结构化程序设计原则的是
无符号二进制整数01001001转换成十进制整数是___________。
A、Theyweresupportiveinwomen’srightsactivity.B、Theypreventedterroristsfromslaughteringpeople.C、Theywereindifferent
Facebook’sSystemofDisablingFakeAccountsA)AliciaIstanbulwokeuponerecentWednesdaytofindherselflockedoutof
最新回复
(
0
)