itgle.com

如下程序的输出是includeusing namespace std;class Base{public:Base( ){cout如下程序的输出是 #include<iostream> using namespace std; class Base{ public: Base( ){cout<<"BB";f( );} void f( ){cout<<"Bf";} }; class Derived:public Base{ public: Derived( ){eout<<"DD";} void f( ){

题目
如下程序的输出是includeusing namespace std;class Base{public:Base( ){cout<<"BB"

如下程序的输出是 #include<iostream> using namespace std; class Base{ public: Base( ){cout<<"BB";f( );} void f( ){cout<<"Bf";} }; class Derived:public Base{ public: Derived( ){eout<<"DD";} void f( ){cout<<"Df";} }; int main( ){Derived d;return 0;}

A.BBBff)D

B.BBDfDDDf

C.DD

D.DDBBBf


相似考题
更多“如下程序的输出是#include<iostream>using namespace std;class Base{public:Base( ){cout<<"BB" ”相关问题
  • 第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题:

    执行如下程序将输出():includeusing namespace std;class Base{public:Base(){cout<<

    执行如下程序将输出( ): #include<iostream> using namespace std; class Base { public: Base(){cout<<"BB";fun();} void fun (){tout<<"Brim";} }; class Derived:public Base { public: Derived(){cout<<"DD";} void fun (){cout<<"Dfun";} }; int main(){Derived d;return 0;}

    A.DD

    B.BBDfunDDDfun

    C.BBBfunDD

    D.DDBBBfun


    正确答案:C
    解析:C++中创建一个类的实例时,如果该类存在基类,将首先执行基类的构造函数,然后执行该类本身的构造函数。本题中首先执行类Base的构造函数,所以将先输出“BB”,然后调用基类成员函数fun(),输出“Bfun”,最后调用子类Derived的构造函数输出“DD”。

  • 第3题:

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

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

    有如下程序: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
    解析:析构函数的调用顺序是,先调用派生类的析构函数,再调用基类的析构函数。