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

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


相似考题
更多“有如下程序:#include<iostream>#include<iosream>using namespace std;class BASE{char c;public ”相关问题
  • 第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题:

    有以下程序:include include using namespace std;class base{private: cha

    有以下程序: #include <iostream> #include <string> using namespace std; class base { private: char baseName[10]; public: base ( ) { strcpy (baseName, "Base"); } virtual char *myName() {

    A.DerivedBase

    B.BaseBase

    C.DerivedDerived

    D.BaseDerived


    正确答案:A
    解析:本题考核虚函数的应用。类Derived是从基类Base公有派生而来的。因此,Derived是基类Base的子类型。主函数中定义了一个基类对象bb和一个派生类对象dd。从程序中可看出,派生类Derived的对象dd交给了处理基类Base的对象的函数showPtr进行处理。由于在基类中函数myName被定义成虚函数,所以在函数showPtr中调用的myName函数为派生类的成员函数mySame,从而输出Derived。然后输出className,即基类名称Base。

  • 第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 include using namespace std;class base {private:char

    有以下程序 #include <iostream> #include <string> using namespace std; class base { private: char baseName[10]; public: base() { strcpy(baseName,"Base"); } virtual char *myName() { return baseName; } char *className() { Return baseName; } }; class Derived: public base { private: char derivedName[10]; public: Derived() { strcpy(derivedName,"Derived" ); } char *myName() { return derivedName; } char *className() { return derivedName; } }; void showPtr(base &p) { cout<<p.myName()<<" "<<p.className(); } int main() { base bb; Derived dd; showPtr(dd); return 0; } 运行后的输出结果为

    A.Derived Base

    B.Base Base

    C.Derived Derived

    D.Base Derived


    正确答案:A
    解析:本题考核虚函数的应用。类Derived是从基类Base公有派生而来的。因此,Derived是基类Base的子类型。main()函数中定义了一个基类对象比和一个派生类对象dd。从程序中可看出派生类Derived的对象dd交给了处理基类Base的对象的函数showPtr进行处理。由于在基类中函数myName被定义成虚函数。所以在函数showPtr中调用的myName函数为派生类的成员函数myName,从而输出Derived。然后输出className,即基类名称Base。

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