ConstOver ( ) { }
Protected int ConstOver ( ) { }
Private ConstOver (int z, int y, byte x) { }
Public Object ConstOver (int x, int y, int z) { }
Public void ConstOver (byte x, byte y, byte z) { }
第1题:
有如下类声明: class XA{ int X; public: XA(int n){x=n;} }; class XB:public XA{ int y; public: XB(int a,int b); }; 在构造函数XB的下列定义中,正确的是( )。
A.XB::XB(inta,int b):x(a),y(b){}
B.XB::XB(int a,int b):XA(a),y(b){}
C.XB::XB(int a,int b):x(a),XB(b){}
D.XB::XB(int a,int b):XA(a),XB(b){}
第2题:
有如下类定义:
class Point{
public:
Point(int xx=0,int yy=0):x(xx),y(yy) { }
private:
int x,y;
};
class Circle:public Point{
public:
Circle(int r):radius(r) { }
private:
int radius;
};
派生类Circle中数据成员的个数是( )。
A、3
B、1
C、5
D、2
答案:A
解析:本题考查默认构造函数和带参数的构造函数,题目中定义一个对象a(2)以及对象数组b[3],共执行3次构造函数,对象指针不调用构造函数。
第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(lO,20,30);
cout<<q->add()<<end1;
}
第4题:
有以下程序: #include<iostream> using namespace std; #definePl 3.14 Class Point {private: int x,y; public: Point(int a,intB) {X=a; y:b;} int getx() <return x;} int gety() {return y;}}; class Circle:public Point {pri
A.314
B.157
C.78.5
D.153.86
第5题:
在下列源代码文件Test.java中,正确定义类的代码是( )。
A.pblic class test { public int x=0; public test(int x) { this. x=x;} }
B.public class Test { public int x=0; public Test(int x) { this. x=x;} }
C.public class Test extends T1,T2{ public int x = 0; public Test(int x){ this. x = x; } }
D.protected class Test extends T2{ public int x = 0; public Test(int x) { this. x = x; } }
第6题:
A.public class test { public int x = 0; public test(int x) { this.x = x; } }
B.public class Test{ public int x=0; public Test(int x) { this.x = x; } }
C.public class Test extends T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }
D.public class
第7题:
有如下类声明: class XA { int x; public: XA(int n){x=n;} }; class XB:public XA { int y; public: XB(int a,int b); }; 在构造函数XB的下列定义中,正确的是
A.XB::XB(int a,int b):x(a),y(b){}
B.XB::XB(int a,int b):XA(a),y(b){}
C.XB::XB(int a,int b):x(a),XB(b){}
D.XB::XB(int a,int b):XA(a),XB(b){}
第8题:
有如下程序: #include<iostream> using namespace std; class Base{ int x; public: Base(int n=0):x(n){cout<<n;} int getX( )const{return x;} }; class Derived:public Base{ int y; public: Derived(int m,int n):y(m),Base(n){tout<<m;} Derived(int m):y(m){cout<<m;} }; int main( ){ Derived dl(3),d2(5,7); return 0; } 程序的输出结果是
A.375
B.357
C.0375
D.0357
第9题:
将下面程序补充完整。
include <iostream>
using namespace std;
class Base{
public:
【 】 fun(){return 0;} //声明虚函数
};
class Derived:public Base{
public:
x,y;
void SetVal(int a,int b){}
int fun(){return x+y;}
};
void 【 】 SetVal(int a,int b){x=a;y=b;} //类Derived成员函数
void main(){
Derived d;
cout<<d.fun()<<endl;
}
第10题:
有如下程序: #include <iostream.h> class x { protected: int a; public: x() { a=1; } }; class x1 : virtual public x { public: x1() { a+=1; cout<<a; } }; class x2 : virtual public x { public: x2() { a+=2; cout<<a; } }; class y : public xl,public x2 { public: y() { cout<<a<<end1; } }; int main() { y obj; return O; } 该程序运行后的输出结果是( )。
A.1
B.123
C.242
D.244