写出程序运行的结果
Public class Base
Public virtual string Hello() {return “Base”;}
Public class Sub:Base
Public override string Hello() {return “Sub”;}
1. Base b = new Base(); b.Hello;
2. Sub s = new Sub(); s.Hello;
3. Base b = new Sub (); b.Hello;
4. Sub s = new Base(); s.Hello;
第1题:
请阅读下述代码,写出程序执行的结果
#include <iostream>
using namespace std;
class CBase
{
public:
virtual void print()
{
cout<< "base" << endl;
}
void DoPrint()
{
print();
}
};
class CChild1: public CBase
{
public:
virtual void print()
{
cout<< "child1" << endl;
}
};
class CChild2: pu
{
public:
virtual void pri
{
cout<< "chil
}
};
void DoPrint(CB
{
base->DoPrint
}
void main()
{
CBase* base =
CChild1* child
CChild2* child
DoPrint(child1
DoPrint(child2
DoPrint(base);
delete base;
base = child1;
base->print();
delete child1;
delete child2;
}
第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> 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
第4题:
有如下程序: #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
第5题:
有以下程序: #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.程序编译时出错
第6题:
阅读下面程序,该程序的运行结果是() 。 class BASE{ char c; public: BASE(char n):c(n){} ~BASE(){cout<<c;} }; class DERIVED : public BASE{ char c; public: DERIVED(char n):BASE(n+1),c(n){} ~DERIVED(){ cout<<c;} }; int main() { DERIVED a('X'); return 0; }
A.XY
B.YX
C.X
D.Y
E.XX
F.YY