有如下程序:include using namespace std;class BASE{public:~BASE() {cout有如下程序: #include <iostream> using namespace std; class BASE{ public: ~BASE() {cout<<"BASE"; } }; class DERIVED: public BASE { public: ~DERIVED() {cout<;"DERIVED"; } }; int main(){DERIVED x; r

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


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

    有如下程序: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
    解析:基类和派生类的析构函数的执行顺序是先执行派生类的析构函数,最后执行基类的析构函数;故先执行DIVERED的析构函数,后执行BASE的析构函数。

  • 第2题:

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

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

    有如下程序:include using namespace std;class Base{public:Base(){ cout<<"BB";f()

    有如下程序: #include <iostream> using namespace std; class Base { public: Base(){ cout<<"BB";f(); } void f() { cout<<"Bf";} }; class Derived:public Base { public: Derived() { cout<<"DD"; } void f(){ cout<<"Df"; } }; int main(){ Derived d; return 0;}执行上面的程序将输出______ 。

    A.BBBfDD

    B.BBDfDDDf

    C.DD

    D.DDBBBf


    正确答案: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