有如下程序: #inc1ude <iostream> using namespace std; class Base { prVate: Void mnl()const{cout<<"fun1";}

admin2020-04-07  20

问题 有如下程序:
    #inc1ude <iostream>
    using namespace std;
    class Base
    {
    prVate:
    Void mnl()const{cout<<"fun1";}
    proteCted:
    Void fun2()const{cout<<”mn2¨;}
    public:
    Void fun3()const{cout<<"fun3";}
   };
    class DeriVed:prOteCted BaSe
    {
    public:
    Void fun4()const{cout<<"fIun4";}
    };
    int main()
    {
    DeriVed obj;
    obj.fun1();    //①
    obj.fun2();    //②
    obj.fun3();    //③
    obj.fun4();    //④
    reurn O:
    }
    其中有语法错误的语句是(     )。

选项 A、①②③④
B、①②③
C、②③④
D、①④

答案B

解析 此题考查的是保护继承。因为Derived以protected方式继承了Base类,所以父类Base中的公有成员和保护成员均成了Derived类的保护成员,而Base类的私有成员Derived类不可访问。所以,主函数中通过Derived类的对象只能够访问到Derived类的公有成员。
转载请注明原文地址:https://kaotiyun.com/show/KV8p777K
0

最新回复(0)