多选题Given the following interface definition, which definitions are valid?()   interface I {   void setValue(int val);   int getValue();   }    DEFINITION a:   (a) class a extends I {  int value;   void setValue(int val) { value = val;  }   int getValue() 

题目
多选题
Given the following interface definition, which definitions are valid?()   interface I {   void setValue(int val);   int getValue();   }    DEFINITION a:   (a) class a extends I {  int value;   void setValue(int val) { value = val;  }   int getValue() {  return value;  }   }   DEFINITION b:   (b) interface b extends I {   void increment();   }   DEFINITION c:   (c) abstract class c implements I {   int getValue() {  return 0;  }  abstract void increment();   }   DEFINITION d:   (d) interface d implements I {  void increment();  }   DEFINITION e:   (e) class e implements I {  int value;   public void setValue(int val) { value = val; }  }
A

Definition a.

B

Definition b.

C

Definition c.

D

Definition d.

E

Definition e.


相似考题
参考答案和解析
正确答案: A,C
解析: 暂无解析
更多“多选题Given the following interface definition, which definitions are valid?()   interface I {   void setValue(int val);   int getValue();   }    DEFINITION a:   (a) class a extends I {  int value;   void setValue(int val) { value = val;  }   int getValue() ”相关问题
  • 第1题:

    ( 10 )已知下列程序的输出结果是 42 ,请将画线处缺失的部分补充完整。

    #include

    using namespace std;

    class Foo {

    int value;

    public:

    Foo( ) : value(0) {}

    void setValue(int value)

    { 【 10 】 = value; // 给 Foo 的数据成员 value 赋值 }

    void print( ) { cout << value; }

    };

    int main( )

    {

    Foo f;

    f.setValue(42);

    f.print();

    return 0;

    }


    正确答案:

  • 第2题:

    有如下类声明; class SAMPLE { int n; public: SAMPLE(int i=0):n(i){} void setValue(int n0); }; 下列关于setValue成员函数的实现中,正确的是( )。

    A.SAMPLE::setValue(int n0){n=n0;)

    B.void SAMPLE::setValue(int n0){n=n0;}

    C.void setValue(int n0){n=n0;}

    D.(int n0){n=n0;}


    正确答案:B
    解析:此题考查了成员函数的定义格式。在类外部对成员函数定义时的一般格式为:返回类型类名::成员函数名(参数表){函数体}。

  • 第3题:

    有以下程序: include usingnamespacestd; classCFactorial { private:intvalue;intfac

    有以下程序:

    include <iostream>

    using namespace std;

    class CFactorial

    {

    private:

    int value;

    int fact;

    public:

    CFactorial ( int val );

    void CalculateFactorial();

    void Display();

    };

    CFactorial :: CFactorial( int val )

    {

    value = val;

    fact = 1;

    }

    void CFactorial :: CalculateFactorial()

    {

    int i = value;

    while ( i > 1 )

    fact *= i--;

    }

    void CFactorial :: Display()

    {

    cout<<value<<"!="<<fact<<end1;

    }

    int main()

    {

    CFactorial A( 5 );

    A.CalculateFactorial();

    A.Display();

    return 0;

    }

    程序中,类CPactorial的功能是【 】,该程序运行的结果是【 】。


    正确答案:求自然数的阶乘 120
    求自然数的阶乘 120 解析:类CFactorial中的成员函数CalculateFactorial()实现的功能是:求自然数value的阶乘结果。

  • 第4题:

    以下程序的输出结果是_____。 include class object {private:int val; public:objec

    以下程序的输出结果是_____。

    include<iostream.h>

    class object

    { private:

    int val;

    public:

    object( ) ;

    object(int i) ;

    ~object( ) ;};

    object: :object( )

    { val=0;

    cout < < "Default constructor for object" < < endl;}

    object: :object(int i)

    { val=i;

    cout < < "Constructor for object" < < val < < endl;}

    object: :~object( )

    { cout < < "Destructor for object" < < val < < endl;}

    class container{ private:

    object one;

    object two;

    int data;

    public:

    container( ) ;

    container(int i,int j,int k) ;

    ~container( ) ;};

    container: :container( )

    { data=0;

    cout < < "Default constructor for container" < < endl;}

    container: :container(int i,int j,int k) :two(i) ,one(j)

    { data=k;

    cout < < "Constructor for container" < < endl;}

    container: :~container( )

    { cout < < "Destructor for container" < < endl;}

    void main( )

    { container anObj(5,6,10) ;}


    正确答案:Constructor for object6 Constructor for object5 Constructor for container Destructor for container Destructor for object5 Destructor for object6
    Constructor for object6 Constructor for object5 Constructor for container Destructor for container Destructor for object5 Destructor for object6 解析:C++语言中的构造函数和析构函数分别是在声明对象时和对象调用完毕后调用,本题中的调用就是这样成对出现的。

  • 第5题:

    下列程序的运行结果是 includeclass Location{private:int X.Y;public:void init(i

    下列程序的运行结果是 #include<iostream.h> class Location{ private: int X.Y; public: void init(int=0,int=0); void valueX(int val){X=val;} int valueX( ){ return X;} void valueY

    A.5 0 6 4

    B.0 0 6 4

    C.5 0 6 2

    D.0 0 6 2


    正确答案:A
    解析:本题中有成员函数和它的重载函数,要注意它们的不同,在本题中先调用了init函数,初始化了X,Y,都为0,valueX(5);又将X变为5,所以输出5和0,然后初始化init(6,2),接着又valueY(4);将X,Y设为6和4,所以输出6和4。

  • 第6题:

    下列程序的运行结果是inClUdeclass Location{private:int X,Y;pubhc:void init(int

    下列程序的运行结果是 #inClUde<iostream.h> class Location{ private: int X,Y; pubhc: void init(int=0,int=0) ; void valueX(int val) {X=val;} int valueX( ) {retum X;} void valueY(int val) {Y=val;} int valueY( ) {retum Y;}};void Location: :init(int initX,int initY) { X=initX; Y=initY;} Void main( ) { Location A,B; A. init( ) ; A. valueX(5) ; cout < < A. valueX( ) < < endl < < A. valueY( ) < < endl; B. init(6,2) ; B. valueY(4) ; cout < < B. valueX( ) < < endl < < B. valueY( ) < < endl;}

    A.5

    B.0

    C.5

    D.0 0 0 0 0 6 6 6 6 4 4 2 2


    正确答案:A
    解析:本题中有成员函数和它的重载函数,要注意它们的不同,在本题中先调用了init函数,初始化了X、Y,都为0,valueX(5) ;又将X变为5,所以输出5和0,然后初始化init(6,2) ,接着又valueY(4) ;将X、Y设为6和4,所以输出6和4。

  • 第7题:

    有如下程序:includeusing namespace std;class MyClass{public: MyClass(int x):val(

    有如下程序: #include<iostream> using namespace std; class MyClass{ public: MyClass(int x):val(x) {} void Print() const {cout<<"const:val="<<val<<'\t';} void Print() {cout<<"val="<<val<<'t';} private: int val; }; int main() const MyClass obj1(10); MyClass obi2(20); obj1.Print(); obj2.Print(); return 0; } 程序的输出结果是( )。

    A.val=10 const:val=20

    B.const:val=10 const:val=20

    C.const:val=10 val=20

    D.val=10 val=20


    正确答案:C
    解析:此题考查的是常成员函数的重载。常成员函数是使用const关键字说明的函数。COHM关键字可用于区分重载函数。此时,常对象调用常成员函数,一般对象调用一般成员函数;题目中的Print()就是通过const重载的两个成员函数,主函数中声明的。obj1是常对象,obj2是一般对象。故输出结果是const::val=10val=20。

  • 第8题:

    有如下类声明: class SAMPLE { int n: public: SAMPLE(int i=0):n(i){} void setValue(int nO); }; 下列关于9etValue成员函数的定义中,正确的是( )。

    A.SAMPLE::setValue(int nO){n=n0;}

    B.void SAMPLE::setValue(int胡){n=n0;

    C.void setValue(int nO){n=n0;}

    D.setValue(int nO){n=n0;}


    正确答案:B
    本题考查在类外定义类的成员函数,需要使用作用域限定符“::”,属于基础知识,本题答案为8。

  • 第9题:

    有如下类声明:class SAMPLE{ int n; public: SAMPLE(int i=0):n(i){} void setValue(int n(0);};下列关于getValue 成员函数的实现中,正确的是( )。

    A.SAMPLE:: setValue(int n0){ n=n0; )

    B.void SAMPLE:: setValue(int n0){ n=n0;}

    C.void setValue (int n0){ n=n0;}

    D.setValue(int n0){ n=n0;}


    正确答案:B

  • 第10题:

    Given the following interface definition, which definitions are valid?()   interface I {   void setValue(int val);   int getValue();   }    DEFINITION a:   (a) class a extends I {  int value;   void setValue(int val) { value = val;  }   int getValue() {  return value;  }   }   DEFINITION b:   (b) interface b extends I {   void increment();   }   DEFINITION c:   (c) abstract class c implements I {   int getValue() {  return 0;  }  abstract void increment();   }   DEFINITION d:   (d) interface d implements I {  void increment();  }   DEFINITION e:   (e) class e implements I {  int value;   public void setValue(int val) { value = val; }  }  

    • A、Definition a.
    • B、Definition b.
    • C、Definition c.
    • D、Definition d.
    • E、Definition e.

    正确答案:B,C

  • 第11题:

    Given the following code:    public class Test {  void printValue(int m){  do {  System.out.println("The value is"+m);     }  while( --m > 10 )     }  public static void main(String arg[]) {     int i=10;  Test t= new Test();     t.printValue(i);     }     }  Which will be output?()    

    • A、 The value is 8
    • B、 The value is 9
    • C、 The value is 10
    • D、 The value is 11

    正确答案:C

  • 第12题:

    多选题
    interface A { public int getValue() }  class B implements A {  public int getValue() { return 1; }  }  class C extends B {  // insert code here  }  Which three code fragments, inserted individually at line 15, make use of polymorphism?()
    A

    public void add(C c) { c.getValue(); }

    B

    public void add(B b) { b.getValue(); }

    C

    public void add(A a) { a.getValue(); }

    D

    public void add(A a, B b) { a.getValue(); }

    E

    public void add(C c1, C c2) { c1.getValue(); }


    正确答案: C,B
    解析: 暂无解析

  • 第13题:

    请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,该工程含有一个源程序文件pn,jl.cpp。其中位于每个注释“//ERROR 木}}水found}}水木”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: The value is 10 注意:只修改注释“//ERROR **** found****”的下一行语句,不要改动程序中的其他内容。 //pmjl.cpp include<iostream> using namespace std; class MyClass{ int value; public: //ERROR********found********* void MyClass(int val):value(val){} int GetValueconst{return value;} void SetValue(int val); }; //ERROR********found******** inline void SetValue(int val){value=val;} int main MyClass obj(O); obj.SetValue(10); //ERROR********found********下列语句功能是输出obj的成员value的值 tout<<”The value is”<<obj.value<<endl: return 0; }


    正确答案:
    (1)MyClass(int val):value(val){}
    (2)void MyClass::SetValue(int val){value=val;}
    (3)cout“”The value is”“obj.GetValue“end1;

  • 第14题:

    有如下程序:includeusing namespace std;class MyClass{public:MyClass(int x):val(x

    有如下程序: #include<iostream> using namespace std; class MyClass{ public: MyClass(int x):val(x){} void Print()const{cout<<“const:val=”<<<val<<‘\’;} void Print(){cout<<“val=”<<val<<‘t’;} private: int va1; }; int main(){ cons

    A.val=10 const:val=20

    B.const:val=10 const:val=20

    C.const:val=10 val=20

    D.val=10 val=20


    正确答案:B
    解析: 本题考查提派生类中构造函数的定义。派生类的构造首先要调用基类的构造函数,对基类成员初始化;然后对派生类中的新增成员初始化。格式:派生类名(构造函数形参表)基类构造函数(形参表)。

  • 第15题:

    有如下类声明: 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=n0;}


    正确答案:B

  • 第16题:

    以下程序段共有错误()处。include using namespaces std;class Sample{private: int n

    以下程序段共有错误( )处。 #include <iostream> using namespaces std; class Sample { private: int n; public: Sample(int i) { n=i; } void setvalue (int i) { n=i; } void display() { cout<<”n=”<<n<<endl; } }; int main() { const Sample a(10); a.setvalue(5); a.display(); return 0; }

    A.1

    B.2

    C.3

    D.4


    正确答案:B
    解析:本题考核常对象、常数据成员和常成员函数。本程序中有两个错误:第1个错误是a.setvalue(5);语句,由于对象a为常对象,所以对象a的私有数据成员n不能被更新;第2处错误是语句a.display();。由于对象a为常对象,所以通过对象a只能调用它的成员函数,而成员函数display()不是常成员函数。

  • 第17题:

    有以下程序:includeusing namespace std;class MyClass{public: MyClass(); ~MyClass

    有以下程序: #include<iostream> using namespace std; class MyClass { public: MyClass(); ~MyClass(); void SetValue(int val); private: static int i; }; int MyClass::i=0; MyClass::MyClass() { i++; cout<<i; } MyClass::~MyClass() { i--; cout<<i; } void MyClass::SetValue(int val) { i=val; } int main() { MyClass*my[2]; int k; for(k=0;k<2;k++) my[k]=new MyClass; for(k=0;k<2;k++) delete my[k]; return 0; } 运行后的输出结果是( )。

    A.1210

    B.1100

    C.1234

    D.输出结果不确定


    正确答案:A
    解析:类MyClass中变量i是静态数据成员,它被MyClass类的所有对象共享,但它不属于任何一个对象,它的作用域是类范围。程序i是用来统计类MyClass所创建对象的个数,每创建一个对象i加1,每删除MyClass类对象i减1。

  • 第18题:

    有如下类声明: class SAMPLE { int n; public: SAMPLE(int i=0):n(i) { } void setValue(int nO); }; 下列关于getValue 成员函数的实现中,正确的是

    A.SAMPLE::setValue(int nO){ n=nO;}

    B.void SAMPLE::setValue(int nO){ n=nO;}

    C.void setValue(int nO){ n=nO;}

    D.(int nO){ n=nO;}


    正确答案:B
    解析:本题考查了成员函数的定义格式。在类外部对成员函数定义的一般格式为:返回类型>类名>::成员函数名>(参数表>)
      {
      函数体>
      }
      故本题的正确答案为选项B。

  • 第19题:

    下列程序的运行结果是( )。 #include<iostream.h> class Loeation{ private: int X,Y; public: void init(int=0,int=0); void valueX(int val){X=val;} int valueX{returnx;} void valueY(int val){Y=val;} int valueY{return Y;}}; void Location::init(int initX,int initY) {X=initX; Y=initY4} void main(X {Location A,B; A.init; B.value X(5); cout<<A.value X<<endl<<A.value Y<<endl; B.init(6,2); B.value Y(4); eout<<B.value X<<endl<<B.value Y<<endl; }

    A.5 0 6 4

    B.0 0 6 4

    C.5 0 6 2

    D.0 0 6 2


    正确答案:A
    本题中有成员函数和它的重载函数,要注意它们的不同,在本题中先调用了init函数,初始化了x、Y,都为0,valueX(5);又将x变为5,所以输出5和0,然后初始化init(6,2),接着又valueY(4);将x、Y设为6和4,所以输出6和4。

  • 第20题:

    若有以下程序:includeusing namespace std;class A{private:int x;public:int z;void

    若有以下程序:#include<iostream>using namespace std;class A {private: int x;public: int z; void setx(int i) { x=i; } int getx () { return x; }}:class B : public A{private: int m;public: int p; void setvalue(int a, int b, int c) { setx(a) ; z=b; m=c; } void display{) { cout<<getx ()<<", "<<z<<", "<<m<<end1; }};int main(){ B obj; obj. setvalue(2,3,4); obj.display(); return 0;} 程序运行以后的输出结果是

    A.产生语法错误

    B.2,3,4

    C.2,2,2

    D.4,3,2


    正确答案:B
    解析:本题考核继承与派生。当类的继承方式为公有继承时,基类的公有成员和保护成员分别作为派生类的公有成员和保护成员,派生类的其他成员可以直接访问它们。其他外部使用者只能通过派生类的对象访问继承来的公有成员。在本题中,数据成员z和函数setx都是基类A的公有成员,它们经过公有继承以后,在派生类B中还是公有成员,而派生类B中的函数setvalue和display都是公有成员,可以通过对象对它们进行访问。所以程序中对各成员的访问是正确的。本程序的功能是输出已设置的各成员的值。

  • 第21题:

    Which line contains a constructor in this class definition?()   public class Counter { // (1)   int current, step;   public Counter(int startValue, int stepValue) { // (2)   set(startValue);   setStepValue(stepValue);  }   public int get() { return current; } // (3)   public void set(int value) { current = value; } // (4)   public void setStepValue(int stepValue) { step = stepValue; } // (5)  }  

    • A、Code marked with (1) is a constructor
    • B、Code marked with (2) is a constructor
    • C、Code marked with (3) is a constructor
    • D、Code marked with (4) is a constructor
    • E、Code marked with (5) is a Constructor

    正确答案:B

  • 第22题:

    interface A { public int getValue() }  class B implements A {  public int getValue() { return 1; }  }  class C extends B {  // insert code here  }  Which three code fragments, inserted individually at line 15, make use of polymorphism?()

    • A、 public void add(C c) { c.getValue(); }
    • B、 public void add(B b) { b.getValue(); }
    • C、 public void add(A a) { a.getValue(); }
    • D、 public void add(A a, B b) { a.getValue(); }
    • E、 public void add(C c1, C c2) { c1.getValue(); }

    正确答案:B,C,D

  • 第23题:

    多选题
    Given the following interface definition, which definitions are valid?()   interface I {   void setValue(int val);   int getValue();   }    DEFINITION a:   (a) class a extends I {  int value;   void setValue(int val) { value = val;  }   int getValue() {  return value;  }   }   DEFINITION b:   (b) interface b extends I {   void increment();   }   DEFINITION c:   (c) abstract class c implements I {   int getValue() {  return 0;  }  abstract void increment();   }   DEFINITION d:   (d) interface d implements I {  void increment();  }   DEFINITION e:   (e) class e implements I {  int value;   public void setValue(int val) { value = val; }  }
    A

    Definition a.

    B

    Definition b.

    C

    Definition c.

    D

    Definition d.

    E

    Definition e.


    正确答案: A,B
    解析: 暂无解析

  • 第24题:

    单选题
    Given the following code:    public class Test {  void printValue(int m){  do {  System.out.println("The value is"+m);     }  while( --m > 10 )     }  public static void main(String arg[]) {     int i=10;  Test t= new Test();     t.printValue(i);     }     }  Which will be output?()
    A

     The value is 8

    B

     The value is 9

    C

     The value is 10

    D

     The value is 11


    正确答案: B
    解析: 此题考察的是do… while循环和 -- 操作符的知识,do…while最少被执行一次,在执行完do中的内容后判断while中的条件是否为true,如果为true的话就再执行do中的内容,然后再进行判断,以此类推直到while的判断为false时退出循环执行循环后面的内容,而—操作符的规则是在变量右边的-- 将先进行运算,然后才是使变量的值减一,而在变量左边的是先将变量的值减一再运算。