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

admin2021-02-22  17

问题 有如下类定义:
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

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

相关试题推荐
最新回复(0)