设有类定义如下:
class Base{
public Base(int i){}
}
public class MyOver extends Base{
public static void main(String arg[]){
MyOver m = new MyOver(10);
}
MyOver(int i){
super(i);
}
MyOver(String s, int i){
this(i);
//Here
}
}
以下哪条语句可以安排在//Here处 ?
A.MyOver m = new MyOver();
B.super();
C.this("Hello",10);
D.Base b = new Base(10);
第1题:
下列类的定义中,有( ) 处语法错误。 class Base { public: Base(){} Base(int i) { data=i; } private: int data; }; class Derive: public Base { public: Derive(): Base(O) { } Derive(int x) { d=x; } void setvalue(int i) { data=i; } private: d; };
A.1
B.2
C.3
D.4
第2题:
为完成下面的程序,应在划线处填入的语句是 #include<iostream> using namespace std; class Base { private: int x; public: Base (int i) { x=i; } ~Base(){} }; class Derived:public Base { public: ______________//完成类Derive构造函数的定义 }; int main() { Derived Obj; return 0; }
A.Derived(int i):Base(i){}
B.Derived(){}
C.void Derived (int i):Base(i){}
D.Derived(int i){Base(i);}
第3题:
如下程序的输出是 #include<iostream> using namespace std; class Base{ public: Base( ){cout<<"BB";f( );} void f( ){cout<<"Bf";} }; class Derived:public Base{ public: Derived( ){eout<<"DD";} void f( ){cout<<"Df";} }; int main( ){Derived d;return 0;}
A.BBBff)D
B.BBDfDDDf
C.DD
D.DDBBBf
第4题:
有以下程序:
include<iostream>
using namespace std;
class Base
{
public:
Base()
{
K=0;
}
int x;
};
class Derivedl:virtual public Base
{
public:
Derivedl()
{
x=10;
}
};
class Derived2:virtua1 public Base
第5题:
有如下程序: #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
第6题:
有以下程序
include <iostream>
using namespace std;
class Base
{
int a;
public:
Base(int x){ a=x; }
void show(){ cout<<a; }
class Derived : public Base
{
int b;
public:
Derived(int i) :Base(i+1),b(i){}
void show() { cout<<b;
};
int main ()
{
Base b(5),*pb;
Derived d(1);
pb=&d;
pb->show ();
return 0;
}
运行后的打印结果是______。
第7题:
有如下程序:
include<iostream>
using namespace std
class Base{
int b;
public:
Base(int i) {b=i;}
Void disp ( ) {cout<<"Base:b="<<b<<''; }
};
class Base1:virtual public Base{
public:
Base1(int i):Base(i){}
};
class Base2:virtual public Base{
public:
Base2(int i):Base(i){}
};
class Derived:public Basepublic Base1{
int d;
public:
Derived(int i ,int j):Base1(j),Base2(j),【 】
{ d=i; }
void disp() {cout<<"Derived:d="<<d<<' ';}
};
int main()
Derived objD(1,2);objD. disp()
objD. Base::disp();
objD. Base1::disp()
objD. Base2::disp();
return 0;
}
请将程序补充完整,使程序在运行时输出:
Derivd:d=1 Base:b=2 Base:b=2 Base:b=2
第8题:
下面程序的打印结果是【 】。
include <iostream>
using namespace std;
class Base
{
public:
Base(int x)
{
a=x;
}
void show()
{
cout<<a;
}
private:
int a;
};
class Derived : public Base
{
public:
Derived(int i) :Base(i+1) ,b(i) { }
void show()
{
cout<<b;
}
private:
int b;
};
int main ( )
{
Base b(5) , *pb;
Derived d(1);
pb=&d;
pb->show();
return 0;
}
第9题:
若有以下程序: #include<iostream> using namespace Std; Class Base {public: Base() {x=0;} int x;}; class Derivedl:virtua1 public Base {public: Derived1() {x=10;}}; class Derived2:virtual1 public Base {public: Derived2()
A.20
B.30
C.10
D.0
第10题:
下面程序的运行结果是( )。 #include<iostream.h> class base{ protected: int a; public: base{cout<<”0”;} }; class basel:virtual base{ public: basel{cout<<”1”;} }; class base2:virtual base i public: base2{cout<<”2”;} }; class derived:public basel,public base2{ public: derived{cout<<”3”;} }; void main derived obj; cout<<endl:
A.0123
B.3120
C.0312
D.3012
第11题:
A.编译错误
B.200
C.100200
D.100
第12题:
在下面横线上填上适当的语句,完成程序。
include<iostream>
using namespace std;
class Base
{
int x;
public:
Base(int i){x=i;}
~Base(){}
);
class Derived:public Base
{
public:
______//完成类Derive构造函数的定义
};
iht main()
{
Derived obj
第13题:
A.private void fun( int n ){ //...}
B.void fun ( int n ){ //... }
C.protected void fun ( int n ) { //... }
D.public void fun ( int n ) { //... }
第14题:
有如下程序: #include<iostream> using namespace std; class BASE { public: ~BASE(){cout<<"BASE";} }; class DERIVED:public BASE { public: ~DERIVED(){cout<<"DERIVED";} }; int main(){DERIVEDx;retum 0;} 执行后的输出结果是
A.BASE
B.DERIVED
C.BASEDERIVED
D.DERIVEDBASE
第15题:
有如下程序: #include<iostream> using namespace std; class Base{ public: Base(int x=0){cout<<x;} }; class Derived:public Base{ public: Derived(int x=0){cout<<x;} private: Base val; }; int main( ){ Derived d(1); return 0; } 程序的输出结果是
A.0
B.1
C.01
D.001
第16题:
有如下程序: #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
第17题:
下面程序的输出结果是【 】。
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;
}
第18题:
下面程序的运行结果是 #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
第19题:
有如下程序; #include <iostream> using namespace std; class Base { public; Base(inti){x=i;} void dispa0{cout<<x<<',';} private; int x; }; class Derived;public Base { public; Derived(int i);Base(i+10) {x=i;) void dispb(){dispa();cout<<x<<end1;} private; int x; }; int main() { Derived b(2) ; b.dispb(); return 0; } 运行的结果是( )。
A.2,2
B.12,2
C.12,10
D.10,2
第20题:
为完成下面的程序,应在划线处填入的语句是( )。 #include <iostream> using namespace std; class Base { private: int x; public: Base(int i) { x=i; } ~Base(){} }; class Derived : public Base { public: _______________ //完成类Derive构造函数的定义 }; int main() { Derived Obj; return 0; }
A.Derived(int i):Base(i){}
B.Derived(){}
C.voidDerived(int i):Base(0){}
D.Derived(int i){Base(i);}
第21题:
下列类的定义中,有( )处语法错误。 class Base { public: Base(){} Base(int i) { data=i; } private: int data; }; class Derive : public Base { public: Derive() : Base(O) {} Derive (int x) { d=x; } void setvalue(int i) { data=i; } private: int d; };
A.1
B.2
C.3
D.4
第22题:
下列程序的运行结果是______。
include<iostream.h>
class Base
{
public:
virtual void func(int i){cout<<"class Base:"<<i<<end1;)
};
class Derived: public Base
{
public:
void func(double d){cout<<"class Derived:"<<d<<endl;}
};
void main( )
{
Base a,*p=a;
Derived b;
p=&b;
(*p).func(3.3);
}
第23题:
下列程序的输出结果是______。
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;
}