首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
46
问题
有如下程序:
#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> voidmain(){inta=2;intb=a+1;cou<<afo<<endl;}
有如下类的定义。横线处的语句是()。classMyClass{public:MyClass(inta=0,intb=0){X=a:Y=b:}
有如下函数模板定义:template<typenameT1,inta2,inta3>T1sum(T1a1){return(a1+a2+a3);}则以下调用中正确的是
请在下列程序中的横线处填写正确的语句: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成为自己的私有
随机试题
如果企业闲置设备很多,管理效率低下,则表明固定资产周转率
肠系膜上动脉与腹主动脉之间夹角在45°之内。()
下列材料中()作为墙基时必须做墙体防潮层。
()不具有法律效力。
班级寝室、活动室的通道要保持畅通。幼儿在室内活动时,活动室可以上锁。()
认真阅读给定材料,整理一份供有关同志参阅的摘要。要求:概述全面,条理清楚,语言流畅,不超过500字。“给定材料12”中提到“环保风暴”的和“绿色消费文化”,请你谈谈对它们的认识和理解,不超过350字。
生活节俭应当成为选拔国家干部的标准。一个不懂得节俭的人,怎么能尽职地为百姓当家理财呢?以下各项都符合题干的断定,除了?
TextThemodernurbanplanningandredevelopmentmovement【C1】______inresponsetothe【C2】______anddirtinessoftheslumarea
Thenewsitemaboutthefireisfollowedbyadetailedreportmade______.
(1)Somedaysoon,youwillaskarobottofetchasliceofpizzafromyourrefrigerator.Onthatday,you’lltrustthattherobo
最新回复
(
0
)