有如下类定义: #include using namespace std; class Point{ public: int GetXY() { return x+y; }

admin2021-02-22  18

问题 有如下类定义:
       #include
       using namespace std;
       class Point{
       public:
           int GetXY() { return x+y; }
       protected:
           void SetXY(int a,int b) { x=a;y=b; }
       private:
           int x,y;
       };
       class Circle:public Point{
       public:
           int GetR() { return radius; }
           int GetAll() { return GetXY()+radius; }
       protected:
           void SetR(int r) { radius=r; }
       private:
           int radius;
       };
       int main(){
           Circle c;
           c.GetXY();       //①
           c.SetXY(3,4);    //②
           c.GetR();        //③
           c.GetAll();      //④
           return 0;
       }
在标注号码的语句行中存在语法错误的是

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

答案B

解析 本题考查派生类对基类成员的访问属性,派生类公用继承基类的保护成员,在派生类中也变为了保护成员,只能在派生类内访问,不能在类外访问,所以B选项错误。
转载请注明原文地址:https://kaotiyun.com/show/76fp777K
0

最新回复(0)