首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: class Base { public: int data; }; class Derived1 : public Base {}; class Derived2 : protected Base {}; int main() { Deriv
有如下程序: class Base { public: int data; }; class Derived1 : public Base {}; class Derived2 : protected Base {}; int main() { Deriv
admin
2020-10-21
17
问题
有如下程序:
class Base {
public:
int data;
};
class Derived1 : public Base {};
class Derived2 : protected Base {};
int main()
{
Derived1 d1;
Derived2 d2;
d1.data = 0; // ①
d2.data = 0; // ②
return 0;
}
下列关于程序编译结果的描述中,正确的是( )。
选项
A、①②皆无编译错误
B、①有编译错误,②无编译错误
C、①无编译错误,②有编译错误
D、①②皆有编译错误
答案
C
解析
本题考查公用继承和保护继承对基类成员的访问属性。在公用继承中,基类的公用成员和保护成员在派生类中保持原有访问属性,其私有成员仍为基类私有。在受保护继承中,基类的公用成员和保护成员在派生类中成了保护成员,其私有成员仍为基类私有。本题中Derived1公用继承Base,所以①编译正确,Derived2保护继承Base,所以②编译不正确。
转载请注明原文地址:https://kaotiyun.com/show/SNyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错,请改正其中的错误,使得程序正常运行,并使程序输出的结果为:sizeof(str1)=5sizeof(str2)=10sizeof(str3)=1注意:不要改动main函数,
数据流图用于抽象描述一个软件的逻辑模型,数据流图由一些特定的图符构成。下列图符名标识的图符不属于数据流图合法图符的是()。
使用VC6打开考生文件夹下的源程序文件modi2.cpp。请完成函数fun(intx),该函数功能是判定X的所有的约数,并且在函数中调用写函数WriteFile0将结果输出到modi2.txt文件中。例如:x=10的约数为1,2,5,10。注意:不要
使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错误,请改正程序中的错误。本程序要求实现的功能为:从键盘输入一个字符串,并将结果保存到文件modi1.txt中。注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误
使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错,请改正其中的错误,使程序正常运行,并且使程序输出的结果为:a=7,b=0a=8,b=10注意:错误的语句在//******error******的下面,修改该语句即可。#i
使用VC6打开考生文件夹下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能:(1)定义复数类CComplex的私有成员变量real和imaginary,分别用来表示复数的实部和虚部,都是doubl
下列选项中不属于面向对象程序设计特征的是()。
下列有关类继承的叙述中,错误的是()。
若要对Data类中重载的加法运算符成员函数进行声明,下列选项中正确的是()。
算法的时间复杂度是指()。
随机试题
企业长期借款的资本成本包括()
男性,15岁。有胫骨近端疼痛、肿胀1个月,夜间痛明显,无明显外伤史。患者摔倒后出现局部肿痛和异常活动,可采用的治疗方法有
基金管理人至少每周公告一次封闭式基金的资产净值和份额净值。()
下列各项中,企业应作为资产在年末资产负债表中反映的有()。
我国历史上推行“罢黜百家,独尊儒术”的皇帝是()。
张某家住北京市东城区,在朝阳区有一处商业用房,市拆迁办(在西城区)决定对其房屋拆迁,张某不服,诉至法院,应由()受理。
1982年《宪法》是新中国的第()部宪法。
大学生学籍管理系统中有关系模式S(S#,Sn,Sg,Sd,Sa),其中属性S#、Sn、Sg、Sd、Sa分别是学生学号、姓名、性别、系别和年龄,关键字是S#。检索全部小于20岁男生姓名的表达式为()
•Readthetextbelowaboutcomputertrends.•Foreachquestion(31-40),writeonewordinCAPITALLETTERSonyourAnswerShee
A—EngineFuelSystemH—theelectricsystemB—LightsandWiresI—powertrainC—StartingSystemJ—one-waydriveD—underpressureK
最新回复
(
0
)