有如下程序: #include<iostream> using namespace std; class AA { int k; protected: int n; void setK(int k){

admin2021-05-06  17

问题 有如下程序:
    #include<iostream>
    using namespace std;
    class AA {
    int k;
    protected:
    int n;
    void setK(int k){this->k=k;}
    public:
    void setN(int n){this->n=n;}
    };
    class BB:public AA{/*类体略*/};
    int main( )
    {
    BB x;
    x.n=1;//1
    x.setN(2);//2
    x.k=3://3
    x.setK(4);//4
    return 0;
    }
    在标注号码的四条语句中正确的是(    )。

选项 A、1
B、2
C、3
D、4

答案B

解析 k是private,对派生类BB不可见,3错误;n、setK是protected,在派生类BB中是protected,对派生类BB的对象不可见,1,4错误;setN是public,在派生类BB中是public,对派生类BB的对象可见,2正确;故本题答案为B选项。
转载请注明原文地址:https://kaotiyun.com/show/8Hfp777K
0

最新回复(0)