itgle.com

下面程序的输出结果是【】。include using namespace std; class base { protected: int下面程序的输出结果是【 】。include <iostream>using namespace std;class base{protected:int a;public:base(){cout<<"0":}};class basel: virtual public base{public:base1(){ cout<<"1";}};class base2 : vir

题目
下面程序的输出结果是【】。include using namespace std; class base { protected: int

下面程序的输出结果是【 】。

include <iostream>

using namespace std;

class base

{

protected:

int a;

public:

base(){cout<<"0":}

};

class basel: virtual public base

{

public:

base1(){ cout<<"1";}

};

class base2 : virtual public base

{

public:

base2(){cout<<"2";}

};

class derived : public base1,public base2

{

public:

derived () {cout<<"3"; }

}

int main ()

{

derived obj;

cout<<end1;

return 0;

}


相似考题
更多“下面程序的输出结果是【】。include <iostream> using namespace std; class base { protected: int ”相关问题
  • 第1题:

    有如下程序:includeusing namespace std;class Base{protected:Base(){cout<<'Base';

    有如下程序: #include<iostream> using namespace std; class Base{ protected: Base(){cout<<'Base';} Base(char c){cout<<c;} }; class Derived:public Base{ public: Derived(char c){cout<<c;} }; int main(){ Derived d('Derived'); return 0; } 执行这个程序屏幕上将显示输出( )。

    A.Derived

    B.DerivedBase

    C.BaseDerived

    D.DerivedDerived


    正确答案:C
    解析:派生类Derived由基类Base公有派生,在派生类构造函数声明时系统会自动调用基类的缺省构造函数。调用Derived d('Derived');后,执行类Derived构造函数的Derived(char c),系统自动调用基类的缺省构造函数Base(),输出字母Base;再执行派生类的构造函数Derived(char c),输出字母Derived。

  • 第2题:

    下面程序的运行结果是includeclass base{protected:int a;public:base( ){cout<<"0

    下面程序的运行结果是 #include<iostream.h> class base{ protected: int a; public: base( ){cout<<"0";} }; class basel:virtual base { public: base1( ){cout<<"1";} }; class base2:virtual base{ public:

    A.123

    B.3120

    C.312

    D.3012


    正确答案:A
    解析:本题考查的是含有虚基类的继承中构造函数的调用顺序,应该先调用基类的构造函数,接着是按照派生类继承列表的顺序依次调用虚基类的构造函数,最后调用派生类自己的构造函数。

  • 第3题:

    下面程序的运行结果是includeclass base{protected: int a;public: base(){cout <<

    下面程序的运行结果是 #include<iostream.h> class base{ protected: int a; public: base(){cout <<"0";} }; class basel:virtual base{ public: basel () {cout <<"1";} }; class base2:virtual base{ public: base2(){cout <<"2";} }; class derived:public basel,public base2{ public: derived(){cout <<"3";} }; void main() { derived obj; cout <<end1; }

    A.123

    B.3120

    C.312

    D.3012


    正确答案:A
    解析:本题考查的是含有虚基类的继承中构造函数的调用顺序,应该先调用基类的构造函数,接着是按照派生类继承列表的顺序依次调用虚基类的构造函数,最后调用派生类自己的构造函数。

  • 第4题:

    如下程序的输出结果是includevoid fun(int & X,inty){intt=x;x=y;y=t;}int main(){in

    如下程序的输出结果是 #include<iostream> void fun(int & X,inty){intt=x;x=y;y=t;} int main( ){ int a[2]={23,42}; fun(a[1],a[0]); std::cout<<a[0]<<","<<a[1]<<std::endl; return 0; }

    A.42,42

    B.23,23

    C.23,42

    D.42,23


    正确答案:B
    解析:参数X是引用传递,传递的是地址:参数Y是值传递,函数fun( )是做X与Y值交换,交换后X的值要被回传给a[1],此时a[1]=a[0]=23。

  • 第5题:

    有如下程序includeusing namespace std;class Base{protected:Base(){cout<<'A';}Bas

    有如下程序 #include<iostream> using namespace std; class Base{ protected: Base(){cout<<'A';} Base(char c){cout<<c;) }; class Derived: public Base{ public: Derived(char c){cout<<c;) }; int main(){ Derived dl('B'); return 0; } 执行这个程序屏幕上将显示输出( )。

    A.B

    B.BA

    C.AB

    D.BB


    正确答案:C