单选题 C++
题号 #2603622

有如下程序:
#include<iostream>
using namespace std;
class Base
{
private:
void funl()const{tout<<”funl”;}
protected:
void fun2()const{tout<<”fun2”;}
public:
void fun3()const{cout<<”fhll3”;}
};
class Derived:protected Base
{
public:
void fhn4()const{cout<<”filn4”;}
};
int main()
{
Derived obj;
obj.funl();//①
obj.fun2();//②
obj.furd();//③
obj.fun4();//④
return U:
}
其中有语法错误的语句是(  )。

进入在线模考

参考答案

B

答案解析

本题考查保护继承中派生类对基类的访问属性,受保护继承中,基类的公用成员和保护成员在派生类中成了保护成员,其私有成员仍为基类私有,保护基类的所有成员在派生类中都被保护起来,在类外不能访问,所以①②③错误。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考