下面程序的运行结果是
#include<iostream.h>
class base{
protected:
int a;
public:
base( ) {cout < < "0";}
};
class base l: virtual base{
public:
base l ( ) {cout < <"1";}
};
class base 2: virtual base{
public:
base2 ( ) {cout < <"2";}
};
class derived: public base 1, public base2{
public:
derived( ) {cout < < "3";}
};
void main( )
{
derive obj;
cout < < endl;
}
A.0123
B.3120
C.0312
D.3012
第1题:
下面程序的输出结果是【 】。
include <iostream>
using namespace std;
class base
{
protected:
int a;
public:
base(){cout<<"0":}
};
class basel: virtual public base
{
public:
base1(){ cout<<"1";}
};
class base2 : virtual public base
{
public:
base2(){cout<<"2";}
};
class derived : public base1,public base2
{
public:
derived () {cout<<"3"; }
}
int main ()
{
derived obj;
cout<<end1;
return 0;
}
第2题:
下面程序的运行结果是( )。 #include<iostream.h> classbase{ protected: inta; public: base(){cout<<"0";} }; classbasel:virtualbase{ public: basel(){cout<<"1";} }; classbase2:virtualbase{ public: base2(){cout<<"2";} }; classderived:publicbasel,publicbase2{ public: derived(){cout<<"3";} }; voidmain() { derivedobj; eout<<endl: }
A.0123
B.3120
C.O312
D.3012
第3题:
下列程序的输出结果是______。
include<iostream.h>
class base
{
int x,y;
public:
base(int i,int j){x=i;y=j;}
virtual int add( ){return x+y;}
};
class three:public base
{
int z;
public:
three(int i,int j,int k):base(i,j){z=k;)
int add( ){return(base::add( )+z);}
};
void main( )
{
three*q=new three(10,20,30);
cout<<q->add( )<<endl;
}
第4题:
下面程序的运行结果是 #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
第5题:
下面程序的运行结果是 #include<iostream.h> class base{ protected: int a; public: base(){cout <<"0";} }; class basel:virtual base{ public: basel () {cout <<"1";} }; class base2:virtual base{ public: base2(){cout <<"2";} }; class derived:public basel,public base2{ public: derived(){cout <<"3";} }; void main() { derived obj; cout <<end1; }
A.123
B.3120
C.312
D.3012