根据下面的程序,可以在主程序中使用的合法语句是(  )。    #include  <iostream>    using namespace std;    class Person{        int age;    public:        

admin2013-05-30  34

问题 根据下面的程序,可以在主程序中使用的合法语句是(  )。    #include  <iostream>    using namespace std;    class Person{        int age;    public:        void SetAge(int x){age=x;}        void ShowAge(){cout<<"the Person’s age is" <<age;}    };    class Student:private Person{        public:int study_code;    };    void main(){        Student wangqiang;        wangqiang.study_code=23;    }

选项 A、wangqiang.age=231
B、wangqiang.Setage(23)
C、wangqiang.ShowAge()
D、wangqiang.study_code=12

答案D

解析 由于是私有继承,基类中所有成员成为派生类中的私有成员,故不能由派生类的对象访问,只有派生类的公有成员可由派生类对象访问。
转载请注明原文地址:https://kaotiyun.com/show/g1Np777K
0

最新回复(0)