有如下程序: #include using namespace std; class XX{ int x; public: XX(intxx=0):x(xx){} int getX(){ret

admin2016-11-25  18

问题 有如下程序:
    #include
    using namespace std;
    class XX{
    int x;  
    public:
    XX(intxx=0):x(xx){}  
    int getX(){return x;}
    };  
    class YY:public XX{
    int y;
    public:
    YY(int xx,int yy):XX(xx),y(yy){}
    int getV(){return getX()+y;}
    };
    int main(){
    YY c(3,4);
    cout<    return 0;
    }
    运行这个程序的输出结果是(    )。

选项 A、3
B、4
C、7
D、10

答案D

解析 由于类YY公开继承自类XX,所以执行表达式c.getV()+e.getX()的值等于3+3+4=10。
转载请注明原文地址:https://jikaoti.com/ti/Pvt0FFFM
0

最新回复(0)