itgle.com

有如下程序:includeusing namespace std;class Base{protected:Base(){cout有如下程序: #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

题目
有如下程序: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


相似考题
更多“有如下程序:#include<iostream>using namespace std;class Base{protected:Base(){cout<<'Base'; ”相关问题
  • 第1题:

    下面程序的运行结果是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
    解析:本题考查的是含有虚基类的继承中构造函数的调用顺序,应该先调用基类的构造函数,接着是按照派生类继承列表的顺序依次调用虚基类的构造函数,最后调用派生类自己的构造函数。

  • 第2题:

    有如下程序:include using namespace std;class BASE{public:~BASE() {cout<<"BASE";

    有如下程序: #include <iostream> using namespace std; class BASE{ public: ~BASE() {cout<<"BASE"; } }; class DERIVED: public BASE { public: ~DERIVED() {cout<;"DERIVED"; } }; int main(){DERIVED x; return 0;} 执行后的输出结果是______ 。

    A.BASE

    B.DERIVED

    C.BASEDERIVED

    D.DERIVEDBASE


    正确答案:D
    解析:析构函数的调用顺序是,先调用派生类的析构函数,再调用基类的析构函数。

  • 第3题:

    有如下程序:includeusing namespace std;class BASE{public:~BASE(){cout<<"BASE";}}

    有如下程序: #include<iostream> using namespace std; class BASE{ public: ~BASE(){cout<<"BASE";} }; class DERIVED:public BASE{ public: ~DERIVED(){cout<<"DERIVED";} }; int main(){DERIVED x;return 0;} 执行后的输出结果是( )。

    A.BASE

    B.DERIVED

    C.BASEDERIVED

    D.DERIVEDBASE


    正确答案:D
    解析:此题考查的是派生类的定义和使用。当对象被删除时,派生类的析构函数就被执行。由于析构函数不能被继承,因此在执行派生类的析构函数时,基类的析构函数也将被调用。执行顺序是先执行派生类的析构函数,再执行基类的析构函数,其顺序与执行构造函数的顺序正好相反。

  • 第4题:

    有如下程序:includeincludeusing namespace std;class BASE{char c;public

    有如下程序: #include<iostream>#include<iosream> using namespace std; class BASE{ char c; public; BASE(char n):c(n){} virtual ~ BASE(){cout<<c;} }; class DERIVED; public BASE{ char c; public: DERIVED (char n): BASE (n+1)

    A.XY

    B.YX

    C.X

    D.Y


    正确答案:A

  • 第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