若有以下程序: #include using namespace std; class A { public: A(int i,intj) { a=i: b=j; }

admin2013-05-30  22

问题 若有以下程序:
    #include
    using namespace std;
    class A
    {
    public:
    A(int i,intj)
    {
    a=i:
    b=j;
    }
    void move(int x,int y)
    {
    a+=x;
    b+=y;
    }
    void show()
    {
    cout(    }
    private:
    int a,b;
    };
    class B:private A
    {
    public:
    B(int i,int j):A(i,j){}
    void fun()
    {
    move(3,5);
    }
    void fl()
    {
    A::show();
    }
    };
    int main()
    {
    B d(3,4);
    d.fun();
    d.fl();
    return0:
    }
    程序执行后的输出结果是(             )。

选项 A、3,4
B、6,8
C、6,9
D、4,3

答案C

解析 此题的执行过程如下:首先B d(3,4);语句调用B类的构造函数:B(int i,intj),B的构造函数中调用基类A的构造函数,使得a=3,b=4;d.fun()会调用函数move(3,5),使得(3,4)和(3,51的对应部分分别相加,最后输出6,9。
转载请注明原文地址:https://kaotiyun.com/show/j2Np777K
0

最新回复(0)