单选题23.int z=5;  24.  25. public void stuff1(int x) {  26. assert (x> 0);  27. switch(x) {  28. case 2: x= 3;  29. default: assert false; } }  30.  31. private void stuff2(int y) { assert (y < 0); }  32.  33. private void stuff3() { assert (stuff4O); } 34.

题目
单选题
23.int z=5;  24.  25. public void stuff1(int x) {  26. assert (x> 0);  27. switch(x) {  28. case 2: x= 3;  29. default: assert false; } }  30.  31. private void stuff2(int y) { assert (y < 0); }  32.  33. private void stuff3() { assert (stuff4O); } 34.  35. private boolean stuff4() { z = 6; return false; }  Which is true?()
A

 All of the assert statements are used appropriately.

B

 Only the assert statement on line 31 is used appropriately.

C

 The assert statements on lines 29 and 31 are used appropriately.

D

 The assert statements on lines 26 and 29 are used appropriately.

E

 The assert statements on lines 29 and 33 are used appropriately.

F

 The assert statements on lines 29, 31, and 33 are used appropriately.

G

 The assert statements on lines 26, 29, and 31 are used appropriately.


相似考题
更多“单选题23.int z=5;  24.  25. public void stuff1(int x) {  26. assert (x 0);  27. switch(x) {  28. case 2: x= 3;  29. default: assert false; } }  30.  31. private void stuff2(int y) { assert (y  0); }  32.  33. private void stuff3() { assert (stuff4O); } 34.  ”相关问题
  • 第1题:

    下面程序的执行结果为 ‘ #include"iostream" using namespace std; class A { int a; public: void Sera(int x){a=x;} void Display_a(){cout<<a<<endl;} }; class B { int b; public: void Setb(int x){ b=x;} void Dispaly_b() {cout<<b<<endl;} }; class C:public A,private B { private: int c; public: void Setc(int x,int y,int z) { c=z;Sera(x);Serb(y);} void Display_c(){cout<<c<<endl;} }; ① void main() ② { ③ C cc; ④ cc.Seta(1); ⑤ cc.Display_a(); ⑥ cc.Setc(2,2,3); ⑦ cc.Dispaly_b(); ⑧ cc.Display_c(); }

    A.输出为2 2 3

    B.有错误在第5行

    C.输出为1 2 3

    D.有错误在第7行


    正确答案:D
    解析:private继承不能调用Display_b函数,public继承可以调用基类中非private成员。注意:类的继承方式public,proctected和private的区别。

  • 第2题:

    下列程序执行之后,将输出 public class exl9 { public static void main(string[] args) { int x=3; int y=7; switch(y/x){ case 1: y*=2; break; case 2: y*=3; break; case 3: y*=4; break; default: y=0; } System.out.print(y); } }

    A.28

    B.21

    C.14

    D.0


    正确答案:B

  • 第3题:

    若有以下程序:includeusing namespace std;class A{private:inta;public:voidseta(in

    若有以下程序: #include <iostream> using namespace std; class A { private: int a; public: void seta(int x) { a=x; } void showa() { cout<<a<<","; } }; class B { private: int b; public: void setb (int x) { b=x; } void showb() { cout<<b<<","; } }; class C :public A,private B { private: int c; public: void setc(int x, inc y, int z) { c=z; seta (x); setb (y); } void showc() { showa (); showb (); cout<<c<<end1; } }; int main () { C c; c. setc(1,2,3); c.showc(); return 0; } 程序执行后的输出结果是

    A.1,2,3

    B.1,1,1

    C.2,2,2

    D.3,3,3


    正确答案:A
    解析:本题考核派生类的应用。本题中类A和类B都是基类。而类C从类A公有派生,从类B处私有派生.所以类C中的函数成员可以访问类A和类B中的公有成员。在类C的函数成员setc中,调用基类A的函数成员seta对A的数据成员a赋值,还调用了基类B的函数成员setb对类B的数据成员b赋值,然后对类C自己的数据成员c赋值。在类C的函数成员showc中,调用基类A的函数成员showa显示数据成员a的值,还调用基类B的函数成员showb显示数据成员b的值,然后输出类C自己的数据成员c的值.在主函数main中,先定义派生类的对象c,然后调用setc对c中的数据成员赋值,然后输出赋值结果。所以程序最后输出应该为:1,2,3。

  • 第4题:

    下列程序的运行结果是( )。 #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。

  • 第5题:

    给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test {  public void cal(int x, int y, int z) { } //A } 

    • A、public int cal(int x,int y,float z){return 0;}
    • B、public int cal(int x,int y,int z){return 0;}
    • C、public void cal(int x,int z){}
    • D、public viod cal(int z,int y,int x){}

    正确答案:A,C

  • 第6题:

    20. public float getSalary(Employee e) {  21. assert validEmployee(e);  22. float sal = lookupSalary(e);  23. assert (sal>0);  24. return sal;  25. }  26. private int getAge(Employee e) {  27. assert validEmployee(e);  28. int age = lookupAge(e);  29. assert (age>0);  30. return age;  31. }  Which line is a violation of appropriate use of the assertion mechanism?()  

    • A、 line 21
    • B、 line 23
    • C、 line 27
    • D、 line 29

    正确答案:A

  • 第7题:

    public class MethodOver {   private int x, y;   private float z;   public void setVar(int a, int b, float c){   x = a;   y = b;   z = c;   }   }   Which two overload the setVar method?()

    • A、 void setVar (int a, int b, float c){  x = a;  y = b;  z = c;  }
    • B、 public void setVar(int a, float c, int b) {  setVar(a, b, c);  }
    • C、 public void setVar(int a, float c, int b) {  this(a, b, c);  }
    • D、 public void setVar(int a, float b){  x = a;  z = b;  }
    • E、 public void setVar(int ax, int by, float cz) {  x = ax;  y = by;  z = cz;  }

    正确答案:B,D

  • 第8题:

    10. class Inner {  11. private int x;  12. public void setX( int x) { this.x = x; }  13. public int getX() { return x; }  14. }  15.  16. class Outer {  17. private Inner y;  18. public void setY( Inner y) { this.y = y; }  19. public Inner getY() { return y; }  20. }  21.  22. public class Gamma {  23. public static void main( String[] args) { 24. Outer o = new Outer(); 25. Inner i = new Inner();  26.int n=10;  27. i.setX(n);  28. o.setY(i);  29. // insert code here  30. System.out.println( o.getY().getX());  31. }  32. }  Which three code fragments, added individually at line 29, produce the output 100?()

    • A、 n = 100;
    • B、 i.setX( 100);
    • C、 o.getY().setX( 100);
    • D、 i = new Inner(); i.setX( 100);
    • E、 o.setY( i); i = new Inner(); i.setX( 100);
    • F、 i = new Inner(); i.setX( 100); o.setY( i);

    正确答案:B,C,F

  • 第9题:

    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()

    • A、 public class Circle implements Shape { private int radius; }
    • B、 public abstract class Circle extends Shape { private int radius; }
    • C、 public class Circle extends Shape { private int radius; public void draw(); }
    • D、 public abstract class Circle implements Shape { private int radius; public void draw(); }
    • E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
    • F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

    正确答案:B,E

  • 第10题:

    单选题
    Which fragment is an example of inappropriate use of assertions? ()
    A

     assert (!(map.contains(x))); map.add(x);

    B

     if (x > 0){}else { assert (x==0); }

    C

     public void aMethod(int x) { assert (x > 0); }

    D

     assert (invariantCondition()); return retval;

    E

     switch (x) { case 1: break; case 2: creak; default: assert (x == 0);


    正确答案: D
    解析: 暂无解析

  • 第11题:

    多选题
    public class MethodOver {  private int x, y;  private float z;  public void setVar(int a, int b, float c){  x = a;  y = b;  z = c;  }  }   Which two overload the setVar method?()
    A

    void setVar (int a, int b, float c){ x = a; y = b; z = c; }

    B

    public void setVar(int a, float c, int b) { setVar(a, b, c); }

    C

    public void setVar(int a, float c, int b) { this(a, b, c); }

    D

    public void setVar(int a, float b){ x = a; z = b; }

    E

    public void setVar(int ax, int by, float cz) { x = ax; y = by; z = cz; }


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

  • 第12题:

    单选题
    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0): “assertion failed”;  System.out.println(“finished”);  }  }  What is the result?()
    A

     finished

    B

     Compilation fails.

    C

     An AssertionError is thrown.

    D

     An AssertionError is thrown and finished is output.


    正确答案: D
    解析: This question is a bit tricky because it lacks the following information: It should include a statement that says whether or not assertions are enabled. If they are indeed enabled, the 
    correction answer is C. but if they are not, the correct answer is A. Assertions are not enabled by default so if the question is not changed, the most logical answer is A.

  • 第13题:

    下列程序的运行结果是 includeclassLocation{ private: int X,Y; public: void init

    下列程序的运行结果是 #include<iostram.h> classLocation{ private: int X,Y; public: void init(int=0, int=0) ; void valueX(int val){X=val:} int valueX(){return X;} void valueY(int val){Y=val;} int valueY(){returnY;}}; void Location∷init(int initX,int initY) { X=initX; Y=initY;} void main() { LocationA,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 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。

  • 第14题:

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

    若有以下程序: #include<iostream> using namespace std; class A { private: int a; public: void seta(int x) { a=x; } void showa() { cout<<a<<","; } }; class B { private: int b; public: void setb(int x) { b=x; } void showb() { cout<<b<<",”; } }; class C:pUblic A,private B { private: int c; public: void setc(int x,int y,int z) { c=z; seta(x); setb(y); } void showc() { showa(); showb(); cout<<c<<end1; } }; int main() { Cc; c.setc(1,2,3); c.showc(); retrun 0; } 程序执行后的输出结果是

    A.1,2,3

    B.1,1,1

    C.2,2,2

    D.3,3,3


    正确答案:A
    解析:本题考核派生类的应用。本题中类A和类B都是基类。而类C从类A公有派生,从类B处私有派生。所以类C中的函数成员可以访问类A和类B中的公有成员。在类C的函数成员setc中,调用基类A的函数成员seta对A的数据成员a赋值,还调用了基类B的函数成员setb对类B的数据成员b赋值,然后对类C自己的数据成员c赋值。在类C的函数成员showc中,调用基类A的函数成员showa显示数据成员a的值,还调用基类B的函数成员showb显示数据成员b的值,然后输出类C自己的数据成员c的值。在主函数main中,先定义派生类的对象c,然后调用setc对c中的数据成员赋值,然后输出赋值结果。所以程序最后输出应该为:1,2,3。

  • 第15题:

    若有以下程序:include using namespace std;class A{private:int a;public:void seta

    若有以下程序:#include <iostream>using namespace std;class A{private: int a;public: void seta(int x) { a=x; } void showa() { cout<<a<<","; }};class B{private: int b;public: void setb(int x) { b=x; } void showb() { cout<<b<<","; }};class C: public A, private B{private: int c;public: void setc(int x, int y, int z) { c=z; seta(x); setb(y); } void showc() { showa(); showb(); cout<<c<<end1; }};int main(){ C c; c.setc(1,2,3); c.showc(); return 0;}程序执行后的输出结果是( )。

    A.1,2,3

    B.1,1,1

    C.2,2,2

    D.3,3,3


    正确答案:A

  • 第16题:

    include<iostream.h>

    class A

    {

    private:

    int x,y;

    public:

    void f1(int i=0,int j=0){x=i;y=j;}

    void print(){cout<<x<<" "<<y<<endl;}

    void f1(int i=0){x=i,y=0;}

    };

    void main()

    {

    A a;

    a.f1(5);

    a.print();

    }


    正确答案:
    a.f1(5);重载函数产生了二义性。应删去其中一个函数f1。

  • 第17题:

    23.int z=5;  24.  25. public void stuff1(int x) {  26. assert (x> 0);  27. switch(x) {  28. case 2: x= 3;  29. default: assert false; } }  30.  31. private void stuff2(int y) { assert (y < 0); }  32.  33. private void stuff3() { assert (stuff4O); } 34.  35. private boolean stuff4() { z = 6; return false; }  Which is true?() 

    • A、 All of the assert statements are used appropriately.
    • B、 Only the assert statement on line 31 is used appropriately.
    • C、 The assert statements on lines 29 and 31 are used appropriately.
    • D、 The assert statements on lines 26 and 29 are used appropriately.
    • E、 The assert statements on lines 29 and 33 are used appropriately.
    • F、 The assert statements on lines 29, 31, and 33 are used appropriately.
    • G、 The assert statements on lines 26, 29, and 31 are used appropriately.

    正确答案:C

  • 第18题:

    public class ConstOver {  public ConstOver (int x, int y, int z)  {  }  }   Which two overload the ConstOver constructor?()   

    • A、 ConstOver ( ) { }
    • B、 Protected int ConstOver ( ) { }
    • C、 Private ConstOver (int z, int y, byte x) { }
    • D、 Public Object ConstOver (int x, int y, int z) { }
    • E、 Public void ConstOver (byte x, byte y, byte z) { }

    正确答案:A,C

  • 第19题:

    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0): “assertion failed”;  System.out.println(“finished”);  }  }  What is the result?()  

    • A、 finished
    • B、 Compilation fails.
    • C、 An AssertionError is thrown.
    • D、 An AssertionError is thrown and finished is output.

    正确答案:A

  • 第20题:

    Which fragment is an example of inappropriate use of assertions? ()

    • A、 assert (!(map.contains(x))); map.add(x);
    • B、 if (x > 0){}else { assert (x==0); }
    • C、 public void aMethod(int x) { assert (x > 0); }
    • D、 assert (invariantCondition()); return retval;
    • E、 switch (x) { case 1: break; case 2: creak; default: assert (x == 0);

    正确答案:C

  • 第21题:

    Which two code fragments are most likely to cause a StackOverflowError?()

    • A、int []x = {1,2,3,4,5};for(int y = 0; y < 6; y++)    System.out.println(x[y]);
    • B、static int[] x = {7,6,5,4};static { x[1] = 8;x[4] = 3; }
    • C、for(int y = 10; y < 10; y++)doStuff(y);
    • D、void doOne(int x) { doTwo(x); }void doTwo(int y) { doThree(y); }void doThree(int z) { doTwo(z); }
    • E、for(int x = 0; x < 1000000000; x++) doStuff(x);
    • F、void counter(int i) { counter(++i); }

    正确答案:D,F

  • 第22题:

    多选题
    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()
    A

    public class Circle implements Shape { private int radius; }

    B

    public abstract class Circle extends Shape { private int radius; }

    C

    public class Circle extends Shape { private int radius; public void draw(); }

    D

    public abstract class Circle implements Shape { private int radius; public void draw(); }

    E

    public class Circle extends Shape { private int radius;public void draw() {/* code here */} }

    F

    public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }


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

  • 第23题:

    单选题
    20. public float getSalary(Employee e) {  21. assert validEmployee(e);  22. float sal = lookupSalary(e);  23. assert (sal>0);  24. return sal;  25. }  26. private int getAge(Employee e) {  27. assert validEmployee(e);  28. int age = lookupAge(e);  29. assert (age>0);  30. return age;  31. }  Which line is a violation of appropriate use of the assertion mechanism?()
    A

     line 21

    B

     line 23

    C

     line 27

    D

     line 29


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