首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class AA{ int k; protected: int n; void setK(int k){this->k=k;}
有如下程序: #include using namespace std; class AA{ int k; protected: int n; void setK(int k){this->k=k;}
admin
2020-04-07
41
问题
有如下程序:
#include
using namespace std;
class AA{
int k;
protected:
int n;
void setK(int k){this->k=k;}
public:
void setN(int n){this->n=n;}
};
class BB:public AA{/*类体略*/};
int main(){
BB x;
x.n=1: //1
x.setN(2); //2
x.k=3; //3
x.setK(4); //4
return 0:
}
在标注号码的四条语句中正确的是( )。
选项
A、1
B、2
C、3
D、4
答案
B
解析
因为类BB公有继承自类AA,所以AA中的保护成员和公有成员在类BB中仍是保护成员和公有成员。在选项B中调用了公有成员函数setN(intn){this->n=n;},对保护成员n进行赋值操作。
转载请注明原文地址:https://kaotiyun.com/show/Z38p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序的输出结果是#include<iostream.h>intmin(inta,intb){if(a<b)returna;elsereturnb;return0;
下列程序的运行结果为()。#include<iostream.h> voidmain(){inta=2;intb=a+1;cou<<afo<<endl;}
有如下函数模板:template<typenameT,typenaineU>Tcast(Uu){returnu;}其功能是将U类型数据转换为T类型数据。已知i为int型变量,下列对模板函数cast的调用中正确的是
请在下列程序中的横线处填写正确的语句:classSample{public:Sample()()~Sample(){}voidSetData(intdata){//将Sample类
下列程序将x、y和z按从小到大的顺序排列,请将下面的函数模板补充完整。template<classT>voidorder(){Talif(x>y){a=x;x=y;y=a;}
设有基类定义: class Cbase { private: int a; protected: int b; public: int c; }; 派生类采用何种继承方式可以使成员变量b成为自己的私有
随机试题
控制结构图也称为()
设立从事证券经纪、证券投资咨询业务的证券公司,必须具备的条件有()。
在其他情况不变而产品需求发生变化时,劳动力需求()。
蛋类一般每天不超过()个为好。
对下图表述正确的是()。
l,3,2,4,5,16,()
,其中a2+c2≠0,则必有________。
设方阵A满足A2-A-2E=O,并且A及A+2E都是可逆矩阵,则(A+2E)-1=_______。
A、B、C、D、B
Lastyear,Iwroteapieceentitled"WhywewronglyfreakoutoverAP?"ThreetofiveAdvancedPlacementcoursesinhighschool
最新回复
(
0
)