以下程序的执行结果为______。
include<iostream>
using namespace std;
class base
{
public:
virtual void who()
{
cout<<"base class"<<endl;
}
};
class derivel:public base
{
public:
void who()
{
cout<<"d
第1题:
有以下程序#include <iostream>using namespace std:class Base{private: char c;public: Base(char n) :c(n) {} ~Base ( ) { cout<<c; }}; class Derived : public Base{private: char c;public: Derived(char n):Base (n+1),c(n) {} ~Derived() { cout<<c; }};int main(){ Derived obj('x'); return 0;} 执行后的输出结果是
A.xy
B.yx
C.x
D.y
第2题:
有如下程序: #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
第3题:
以下程序的执行结果为______。
include<iostream.h>
class A
{public:A(){cout<<“a”;}
~A(){cout<<“b”;}};
class B:public A
{public:
B(){cout<<“c”;)
~B(){cout<<“d”;}};
void main()
{B b;}
第4题:
有以下程序: #include <iostream> using namespace std; class Base { public: Base(){} virtual void who() { cout<<"Base Class"<<end1; } ~Base(){} }; class Derivel : public Base { public: void who() { cout<<"Derivel Class"<<end1; } }; class Derive2 : public Base { public: void who () { cout<<"Derive2 Class"<<end1; } }; int main () { Base *p; Derivel obj1; Derive2 obj2; p=&obj1; p=&obj2; p->who ( ); return 0; } 执行程序后的输出结果是( )。
A.Base Class
B.Derivel Class
C.Derive2 Class
D.程序编译时出错
第5题:
有以下程序 #include<iostream> using namespace std; class Base { private: char c; public: Base(char n):c(n){} ~Base() { cout<<c; } }; class Derived:public Base { private: char c; public: Derived(char n):Base(n+1),c(n){} ~Derived() { cout<<c; } }; int main() { Derived obj('x'); return 0; } 执行后的输出结果是
A.xy
B.yx
C.x
D.y