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

admin2019-05-06  27

问题 有如下程序:
    #include
    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

解析 因为类BB公有继承自类AA,所以AA中的保护成员和公有成员在类BB中仍是保护成员和公有成员。在选项B中调用了公有成员函数setN(int n){this->n=n;),对保护成员n进行赋值操作。
转载请注明原文地址:https://kaotiyun.com/show/ks8p777K
0

最新回复(0)