以下程序的执行结果是______。
include<iostream.h>
class base
{
public:
virtual void who(){cout<<"base class"<<endl:}
};
class derrvel:public base
{
public:
void who(){cout<<"derivel class"<<endl:}
};
class derive2;public base
{
public:
void who() {cout<<"derive2 class"<<endl;}
};
void main()
{
base obj1,*P;
derive1 obj2;
derive2 obj3:
p=&obj1;
p->who();
p=&obj2:
p->who();
p=&obj3;
p->who();
}
第1题:
下面程序的运行结果是 #include<iostream.h> class base{ protected: int a; public: base( ){cout<<"0";} }; class basel:virtual base { public: base1( ){cout<<"1";} }; class base2:virtual base{ public:
A.123
B.3120
C.312
D.3012
第2题:
有以下程序: #include <iostream> using namespace std; class BASE { private: char c; public: BASE(char n):c(n);{} virtual~BASE() { cout<<c; } }; class DERIVED:public BASE { char c; p
A.XY
B.YX
C.X
D.Y
第3题:
以下程序执行后的输出结果是 ( )。 #include <iostream.h> class Basel { public: void fun(){ cout<<"Basel"<<end1; } }; class Base2 { public: void fun() { cout<<"Base2"<<end1; } } class Derived : public Basel,public Base2 { }; void main() { Derived Obj; Obj.fun(); }
A.Basel
B.Base2
C.BaselBase2
D.程序产生二义性
第4题:
以下程序执行结果是 ( )。 #include <iostream.h> class Base { public virtual void fun() { cout<<"B"; } }; class Derived { public: Derived() { cout<<"D"; } virtual void fun(){ Base::fun(); cout<<"C"; } } int main () { Base *ptr; Derived obj; ptr=&obj; p->fun ( ); return 0; }
A.DBC
B.DCB
C.BDC
D.CBD
第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.程序编译时出错