ZTE 继承与访问控制

#include<iostream>
#include<stdio.h>

using namespace std;

class Test;
class Base { 
protected:  
int mltem; 
private:   
int mCount;   
friend class Test; 
}; 

class Sub:public Base { 
public:  
void Test(const Sub& sub,const Base& base)  
{    
int i=mltem;   //(A)
i = sub.mltem;   //(B)  
i = base.mltem;  //(C)  
} 
}; 

class Test 
{  
public:   
int Count(const Base& base)  
{    
return base.mCount;  // (D)  
} 
};

int main() {
// your code goes here
return 0;
}

【解析】

答案:C

1.公有继承:

派生类可以访问基类的非私有成员;

派生类对象可以访问基类的公有成员;

2.私有继承与保护继承:

派生类可以访问基类的非私有有成员;

派生类对象不可以访问基类的所有成员;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值