有如下程序: #include<iostream> using namespace std; class Base { private: void funl()const {cout<<"funl";} protected: void fun2() const{cout<<"fun2";} public; void fun3() const {cout<<"fun3";} }; class Derived:protected Base {public;void fun4() const {cout<<"fun4";} }; int main() { Derived obj; obj.funl();//① obj.fun2();//② obj.fun3();//③ obj.fun4()://④ return 0; } 其中有语法错误的语句是
A.①②③④
B.①②③
C.②③④
D.①④
参考答案:B
解析: 本题考查的知识点是保护继承。题目中的Derived类保护继承了Base类,因此Base类中的公有成员与保护成员均成了Derived类的保护成员,而Base类的私有成员Derived类不可访问。所以,主函数中通过Derived类的对象只能够访问到 Derived类的公有成员,即只能调用fun4()函数。故应该选择B。