[单选题]

有如下类说明: class TestClass{ int x; public: TestClass(int n){x=n;} }; class TestClass1:public TestClass{ int y; public: TestClass1(int a,int b); }; 在构造函数TestClass1的下列定义中,正确的是( )。

A.TestClass1::TestClass1 (int a,int b):x(a),y(b){}

B.TestClass1::TestClass1 (int a,int b):TestClass(a),y(b){}

C.TestClass1::TestClass1 (int a,int b):x(a),TestClass1(b){}

D.TestClass1::TestClass1 (int a,int b):TestClass(a),TestClass1(b){}

参考答案与解析:

相关试题

有如下类定义:class Test{int x_,y_;public:Test

[单选题]有如下类定义: class Test { int x_,y_; public: Test ():a_(0) ,b_(0) {} Test(int a,int b=0) :a_(a),b_(b){} }; 若执行语句 Test x(2) ,y[3],*z[4]; 则Test类的构造函数被调用的次数是( )。A.2次B.3次C.4次D.5次

  • 查看答案
  • 有如下类声明:class TestClass{ int n; public: T

    [单选题]有如下类声明: class TestClass { int n; public: TestClass(int i=0):n(i){} void setValue(int n0); }; 下面关于setValue成员函数的实现中,正确的是( )A.TestClass::setValue(int n0){n=n0;)B.void TestClass::setValue(int n0){n=n0;}C.void setValue(int n0){n=n0;}D.setValue(int n0){n=n

  • 查看答案
  • 有如下程序public class Test{int a,b;Test ( ){

    [单选题]有如下程序 public class Test { int a,b; Test ( ) { a = 100; b = 200; } Test(int x, int y) { a = x; b = y; } public static void main(String args[]) { Test Obj1 = new Test(12,45); System.out.println("a = "Obj1.a+" b = "+ObB) ; Test Obj1 = new Test(); Sy

  • 查看答案
  • 有如下类声明: class XA { int x; public: XA(int

    [单选题]有如下类声明: 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):

  • 查看答案
  • 有如下类声明: class XA{ int x; public: XA(int

    [单选题]有如下类声明:class XA{int x;public:XA(int U)}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

  • 查看答案
  • 有如下类定义:class Test{public:Test(){ a = 0;

    [单选题]有如下类定义:class Test{public:Test(){ a = 0; c = 0;} // ①int f(int a)const{this->a = a;} // ②static int g(){return a;} // ③void h(intB. . {Test::b = b;}; // ④private:int a;static int b;const int c;};int Test::b = 0;在标注号码的行中,能被正确编译的是A. . ①B. . ②C. . ③D.

  • 查看答案
  • 有如下类定义: class Test { public: Test(){a=0;

    [单选题]有如下类定义: class Test { public: Test(){a=0;c=0;} //① int f(int a)const {this->a=a;} //② static int g(){return a;} //③ void h(int b){Test::b=b;}; //④ private: int a; static int b; const int c; }; int Test::b=0; 在标注号码的行中,能被正确编译的是A.①B.②C.③D.④

  • 查看答案
  • 有如下类定义:class Test { private int x; publi

    [单选题]有如下类定义: class Test { private int x; public int y; public void setX (int m) {x=m;} public int getX( ) {return x;} }现用Test t=new Text();生成一个对象t,则如下语句中,错误的是( )。A.t.x=10;B.t.y=10;C.t. setX(10);D.int m=t.getX( );

  • 查看答案
  • 有如下类声明:class XA{int x;public:XA(int n){x

    [单选题]有如下类声明: 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

  • 查看答案
  • 有如下类声明:class XA{int X;public:XA(int n){x

    [单选题]有如下类声明: class XA{ int X; public: XA(int n){x=n;} }; class XB:publicXA{ 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)

  • 查看答案
  • 有如下类说明:class TestClass{int x;public:Test