问题 单项选择题

有如下程序:
#include <iostream.h>
using namespace std;
class Base

protected:
int i:
public:
int j;
;
class Derived: public Base

int m:
public:
int n;

int main()

Derived d:
d.i=0;//[1]
d.J=0;//[2]
d.m=0;//[3]
d.n=0://[4]
return 0;

其中主函数中有两个赋值语句有错,这两个错误的赋值语句是

A.[1]和[2]

B.[1]和[3]

C.[2]和[3]

D.[2]和[4]

答案

参考答案:B

解析: 本题考核类和派生类的访问权限。类Derived共有继承Base,那么d对基类Base成员变量的访问权限不变,由于数据成员 i为保护的,不能通过对象访问。派生类Derived中变量m为私有的,同样不能通过对象访问,所以错误的赋值语句为[1]和[3]。

单项选择题
单项选择题