首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下类声明: class Base { protected: int amount; public: Base(int n=0):amount(n) { } int getAmount( )const {r
有如下类声明: class Base { protected: int amount; public: Base(int n=0):amount(n) { } int getAmount( )const {r
admin
2019-05-22
18
问题
有如下类声明:
class Base {
protected:
int amount;
public:
Base(int n=0):amount(n) { }
int getAmount( )const {return amount;}
};
class Derived:public Base {
protected:
int value;
public:
Derived(int m,int n):value(m),Base(n) { }
int getData()const{return value+amount;}
};
已知x是一个Derived对象,则下列表达式中正确的是( )。
选项
A、x.value+x.getAmount( )
B、x.getData( )-x.getAmount( )
C、x.getData( )-x.amount
D、x.value+x.amount
答案
B
解析
本题考查公有继承中派生类对象对基类的访问属性。在公有继承中,派生类对象只能私有成员。题中λ足派生类的对象,只能访问基类中公有的Base( )和getAmount( )成员,而不能访问保护类型的amount成员,故选项C、D错误。而类对象对类成员的访问也存在类似的情况,即类对象只能访问类的公有成员,而value是Derived的保护成员,所以A选项也错误。故答案为B。
转载请注明原文地址:https://kaotiyun.com/show/JI8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列有关类继承的叙述中,错误的是
(*p)(x,y)一个函数总是占用一段连续的内存区,而函数名就是该函数所占内存区的首地址。我们可以把函数的这个首地址(或称入口地址)赋予一个指针变量,使该指针变量指向该函数。然后通过指针变量就可以找到并调用这个函数。我们把这种指向函数的指针变量称为“函数指
22,19,13,6,24,38,43,32根据快速排序的定义,取第一个元素24为依据,将小于24的置于其前面,大于24的置于其后面,则可得到快速排序第一趟的结果。
A、 B、 C、 D、 B因为对象a被定义为常对象,所以a.disp()语句调用的是类的常成员函数voiddispoconst,输出的结果是disp2。
A、 B、 C、 D、 C此题考查的是函数重载的概念。在C语言中,允许定义一系列函数名相同,但形参的个数和类型不完全相同的函数,即函数的重载。重载函数对返回值类型不做要求,返回值类型也不参与区分函数的重载形式
break此题考查的是流程控制语句。“只在循环语句或switch语句中使用”的流程控制语句只有break。
A、 B、 C、 D、 B算法的空间复杂度一般是指:执行这个算法所需要的存储空间,其中包括算法程序所占的空间、输入的初始数据所占用的存储空间以及算法执行过程中所需要的额外空间。
下列关于栈的叙述中,正确的选项是()。A)在栈中只能删除数据B)在栈中只能插入数据C)栈是先进先出的线性表D)栈是先进后出的线性表
有如下程序:#include<iostream>usingnamespacestd;classtest{private:inta;public:test(){cout<<"c
要利用C++流实现输入输出的各种格式控制,必须在程序中包含的头文件是()。A)fstreamB)istrearaC)ostreamD)iomanip
随机试题
治疗瘀热内阻型经行发热的首选方剂为:
脊柱结核最常发生的部位是
医德对医学实践具有实际的指导意义,称为医德的
简述普通钢筋拉伸试验的步骤。
以下关于劳动定员与劳动定额的说法,错误的是()。
阅读材料完成下列问题。孟子《鱼我所欲也》原文鱼,我所欲也;熊掌,亦我所欲也。二者不可得兼,舍鱼而取熊掌者也。生,亦我所欲也;义,亦我所欲也。二者不可得兼,舍生而取义者也。生亦我所欲,所欲有甚于生者,故不为苟得也;死亦我所恶,所恶有甚于死
明明在集体教学活动中注意力很难集中,是个“坐不住的孩子"。有时他会“骚扰”周围的小朋友而打断老师正在进行的教学活动;对于老师布置的任务,常常不能很好地完成;他想和小朋友一起活动却因为采取不适当的方式而被拒绝,周围的小朋友经常在老师面前告他的状。老师对于这个
下列文种属于狭义司法文书的是()。
根据以下资料。回答96—100题。如果“全员劳动生产率”为“工业增加值/全部从业人员平均人数”,那么2004年的全部从业人员平均人数为多少?()
Such______thecase,therearenogroundstojustifyyourcomplaints.
最新回复
(
0
)