首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: 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-06-29
34
问题
有如下程序:
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/WZ8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#include<iostream>usingnamespacestd;classONE{public:virtualvoidf(){cout<<"1";}};
软件是程序、数据和______________的集合。
关于友元,下列说法错误的是______。
当在使用类模板时,类模板本身被实例化咸了一个具体的______。
按照标识符的要求,下列选项中,()符号不能组成标识符。
若执行下面的程序时,从键盘上输入3和4,则输出结果是main(){inta,b,s;cin>>a>>b;s=a;if(a<B)s=b;s=s*s;cout<<s<<e
有如下函数模板定义:templateT1Fun(T2n){returnn*5.0;)若要求以int型数据9作为函数实参调用该模板,并返回一个double型数据,则该调用应表示为()。
有如下的运算符重载函数定义:doubleoperator+(inti,intk){returndouble(i+k);}但定义有错误,对这个错误最准确的描述是()。
已知枚举类型定义语句为:enumToken{NAME,NUMBER,PLUS=5,MINUS,PRINT=10};则下列叙述中错误的是()。
软件按功能可以分为应用软件、系统软件和支撑软件(或工具软件)。下面属于应用软件的是( )。
随机试题
“文化大革命”结束的标志是
金属桥用栅栏式的铸道其优点A.各个铸道的长度一致,有利于防止收缩变形B.各个铸道的长度一致,有利于铸件的切割C.各个铸道的长度一致,有利于包埋D.各个铸道的长度一致,有利于铸造E.各个铸道的长度一致,有利于操作
A.补气升提B.健脾利湿C.补肾固脱D.温肾纳气E.收涩固脱
建设项目所处的地区不同,决定了其建设费用的项目类别及其费率存在差异。()
《建设工程安全生产管理条例》规定,不属于监理单位安全生产管理责任和义务的是( )。
某甲在一胡同口抢劫一女青年钱包,抢到钱包后,突然发现该女青年是自己的邻居,于是将钱包当面送还给女青年,并声称刚才的行为是开玩笑的。某甲的行为是()。
企业收到投资者以外币投入的资本,无论是否存在合同约定汇率,均不采用合同约定汇率折算,应采用交易日即期汇率折算,外币投入资本与相应的货币性项目的记账本位币金额相等,不产生外币资本折算差额。()
行为目标描述的是()。
材料一:今年2月27日,全国“两会”前夕,国务院总理温家宝时隔一年之后二次与网友进行在线交流。在两个小时的访谈中,温家宝坦诚深入地回答了网友们内心的诸多问题。在谈到最近两次受到广泛关注的“问题奶粉”时,温总理重申“企业家的身上应该流淌着道德的血液。”今年4
(1)新民主主义理论(2)列宁主义(3)剩余价值理论(4)农村包围城市理论(5)科学发展观
最新回复
(
0
)