首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class Base { private: void fun1() const { cout
有如下程序: #include using namespace std; class Base { private: void fun1() const { cout
admin
2015-07-22
52
问题
有如下程序:
#include
using namespace std;
class Base
{
private:
void fun1() const { cout<<"fun1"; }
protected:
void fun2() const { cout<<"fun2"; }
public:
void fun3() const { cout<<"fun3"; }
};
class Derived : protected Base
{
public:
void fun4() const { cout<<"fun4"; }
};
int main()
{
Derived obj;
obj.fun1(); // ①
obj.fun2(); // ②
obj.fun3(); // ③
obj.fun4(); // ④
return 0;
}
其中有语法错误的语句是( )。
选项
A、①②③④
B、①②③
C、②③④
D、①④
答案
B
解析
本题考查保护继承中派生类对基类的访问属性,受保护继承中,基类的公用成员和保护成员在派生类中成了保护成员,其私有成员仍为基类私有,保护基类的所有成员在派生类中都被保护起来,在类外不能访问,所以①②③错误。
转载请注明原文地址:https://kaotiyun.com/show/W5Np777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#include<iostream>usingnamespacestd;classDA{intk;public:DA(intx=1):k(x){}~DA(){cout<<k;}};intmain(
如下类定义中包含了构造函数和拷贝构造函数的原型声明,请在横线处填写正确的内容,使拷贝构造函数的声明完整。ClassmyClass{private:intdata;public:myClass(intvalue);//构造函数
有如下定义:classMA{intvalue;public:MA(intn=0):value(n){}};MA*ta,tb;其中MA类的对象名标识符是【】。
有如下函数模板:template<class T>T square(T x){return x*x;}其中T是
请在如下程序中的空格处填写正确的语句:#include<iostream>usingnamespacestd;classBase{public:voidfun(){cout<<"Basefun
有如下程序: #include <iostream> using namespace std; class B { public: virtual void show() { cout<<"B"; } };
如下程序声明了一个使用两个通用数据类型的模板类dataClass,其中构造函数用于初始化两个数据成员,成员函数show用于输出两个数据成员的数值。#include<iostream>usingnamespacestd;【
随机试题
根据激励过程的期望理论,激励力、效价和期望值之间的关系可以表示为()
患者,男,47岁。下肢弛缓无力1年余,肌肉明显萎缩,功能严重受限,并感麻木,发凉,腰酸,头晕,舌红少苔,脉细数。治疗应首选
关于减刑、假释的适用,下列哪些选项是错误的?(2013年卷二57题)
设备制造监理的主要工作内容不包括()。
《中华人民共和国宪法》规定公民的通信自由和通信秘密受法律保护。下列说法正确的是()。
从所给的四个选项中,选择最合适的一个填入问号处,使之呈现一定的规律性。
Populationstendtogrowatanexponential(指数的)rate.Thismeansthattheyprogressivelydouble.Asanexampleofthistypeof
"Freebie"marketingA.Inthelate18905.whiletravelingasanitinerantsalespersonfortheCrown.CorkandSealCompany.K
Morethan40yearsago,LeeKuanYew【B1】______whatwasapoor,decayingcolonyintoashining,richandmodemcity,allthetim
国外的游客们可以在除上海、北京这些主要的大城市(metropolises)之外的其他地方寻找让人兴奋的中国地道美食(delicacy)。在2010年被联合国教科文组织(UNESCO)誉为亚洲第一个“美食城市”(CityofGastronomy)的成都就是
最新回复
(
0
)