有如下类定义: class AA { int a; Public: AA(int n=0):a(n) {} }; class BB :public AA { public: BB(int n)________________ }; 其中横线处的缺失部分是(

admin2021-02-22  25

问题 有如下类定义:
class AA {
int a;
Public:
AA(int n=0):a(n) {}
};
class BB :public AA {
public:
BB(int n)________________
};
其中横线处的缺失部分是(    )。

选项 A、:a(n) {}
B、:AA(n) {}
C、{ a(n); }
D、{ a=n; }

答案B

解析 本题考查公用继承对基类成员的访问属性。公用继承中,基类的公用成员和保护成员在派生类中保持原有访问属性,其私有成员仍为基类私有,本题中若要给派生类继承下来基类的私有成员赋值,那么只能调用基类的成员函数来对它赋值,成员变量默认的访问权限为私有,即a为私有变量。所以本题答案为B。
转载请注明原文地址:https://kaotiyun.com/show/WEfp777K
0

最新回复(0)