niusouti.com

( 31 )有如下类定义:class XX{int xx;public:XX ( ) : xx ( 0 ) {cout<<' A';}XX ( int n ) : xx ( n ) {tout<<' B';}};Class YY:public XX{Int yy;public:YY ( ) : yy ( 0 ) {cout+yy;}YY ( int n ) : XX ( n+1 ) , yy ( n ) {cout<<yy;}YY ( int m, int n ) : XX ( m ) , yy ( n

题目

( 31 )有如下类定义:

class XX{

int xx;

public:

XX ( ) : xx ( 0 ) {cout<<' A';}

XX ( int n ) : xx ( n ) {tout<<' B';}

};

Class YY:public XX{

Int yy;

public:

YY ( ) : yy ( 0 ) {cout+yy;}

YY ( int n ) : XX ( n+1 ) , yy ( n ) {cout<<yy;}

YY ( int m, int n ) : XX ( m ) , yy ( n ) {cout<<yy;}

};

下列选项中,输出结果为 A0 的语句是

A ) YY y1(0,0);

B ) YY y2(1);

C ) YY y3(0);

D ) YY y4;


相似考题
更多“( 31 )有如下类定义:class XX{int xx;public:XX ( ) : xx ( 0 ) {cout&lt;&lt;' A';}XX ( int n ”相关问题
  • 第1题:

    有如下程序:includeusing namespace std;class XX{protected;int k;public:XX(int n=

    有如下程序: #include<iostream> using namespace std; class XX{ protected; int k; public: XX(int n=5):k(n){} ~XX(){cout<<"XX";} Virtual void f()cons=0; }; inline void XX::f()const{cout<<k+3;} class YY:public XX{ public:

    A.28XX

    B.28YYXX

    C.-33XX

    D.-33XXYY


    正确答案:A

  • 第2题:

    有如下类定义:

    classXX{

    intxdata;

    public:

    XX(intn=0):xdata(n){}

    };

    classYY:publicXX{

    intydata;

    public:

    YY(intm=0,intn=O):XX(m),ydata(n){}

    };

    YY类的对象包含的数据成员的个数是( )。

    A.1

    B.2

    C.3

    D.4


    正确答案:B
    B。【解析】本题主要考查派生类的继承方式。该题为公有继承,它包含基类中全部数据成员和除了构造、析构函数之外的全部成员函数,本题数据成员的个数即为2。

  • 第3题:

    有如下程序:includeusingnamespacestd;classXX{protected: intk;public: XX(intn=5):

    有如下程序: #include <iostream> using namespace std; class XX { protected: int k; public: XX(int n=5):k(n){} ~XX() { cout<<"XX"; } virtual void f() const=0; }; inline void XX::f()

    A.28XX

    B.28YYXX

    C.-33XX

    D.-33XXYY


    正确答案:A
    解析:本题中,&p是一个对象指针,通过使用new运算符变成了指向派生类YY的对象指针。所以当建立并初始化对象指针&p时,程序将调用基类XX的构造函数,给私有数据成员k赋值5。然后调用派生类YY的常成员函数f(),输出值2和8。最后调用基类XX的析构函数输出XX。

  • 第4题:

    有如下类定义:

    class XX{

    int XX;

    public:

    xx():xx(0){tout<<A;}

    XX(int n):xx(n){cout<<B;}

    };

    class Y:Y:public XX{

    int YY;

    public:

    YY():YV(O){cout<<YY;)

    YY(int n):xx(n+1),YY(n){cout<<YY;}

    YY(int m,int n):XX(m),YY(n){cout<<yy;)

    };

    下列选项中,输出结果为A0的语句是

    A.YY yl(0,0);

    B.YY 72(1);

    C.YY y3(0);

    D.YY y4;


    正确答案:D
    解析:建立派生类对象时,构值函数的执行顺序为:执行基类的构造函数一执行成员对象的构造函数一执行派生类的构造函数。D)选项定义对象y4时没有传人任何值,则先调用基类的构造函数.XX( ),输出‘A。,然后调用派生类的构造函数YY( ),输出yy=0,最终输出为A0。故本题答案为D)。

  • 第5题:

    有如下类定义: class XX{ int xdata: public: xx(int n=0):xdata(n){} } class YY:public XX{ int ydata; public: YY(int m=0,int n=0):xx(m),ydata(n){ } {; YY类的对象包含的数据成员的个数是

    A.1

    B.2

    C.3

    D.4


    正确答案:B
    解析:派生类继承基类,继承了基类的数据成员和成员函数,加上派生类自己新定义的数据成员,所以该类应该有2个数据成员。