单选题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. asser”相关问题
  • 第1题:

    若有以下程序:include using namespace std;class A{private: int x;protected: int

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

    A.产生语法错误

    B.7,6,5

    C.5,6,7

    D.7,5,6


    正确答案:C
    解析:本题考核保护继承中对类成员的访问权限。①在保护继承中,基类公有成员和保护成员都以保护成员身份出现在派生类中,而基类私有成员不可访问。②基类的公有成员和保护成员被继承以后作为派生类的保护成员,这样,派生类的其他成员可以直接访问它们。③由保护派.生的类声明的对象,不能访问任何基类的成员。在本题中,基类A中的数据成员y和函数setx,经过保护继承以后,在派生类B中成为保护成员,派生类B的对象不能访问它们。而派生类B中的函数setvalue和display都是公有成员,可以通过对象对它们进行访问。所以程序中对各成员的访问是正确的。本程序的功能是对类中各数据成员进行赋值,然后查看赋值是否正确。

  • 第2题:

    若有以下程序: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。

  • 第3题:

    若有以下程序: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

  • 第4题:

    下列程序运行后的输出结果是()。 include void fun(int,int,int*); void main() { i

    下列程序运行后的输出结果是( )。 #include<iostream.h> void fun(int,int,int*); void main() { int x,y,z; fun(5,6,&x); fun(7,x,&y); fun(x,y,&z); cout<<x<<","<<y<<","<<z<<end1; } void fun(int a,int b,int *c) { b+=a; *c=b-a; }

    A.5, 5, 5

    B.6, 6, 6

    C.5, 6, 7

    D.7, 7, 7


    正确答案:B
    解析:由程序中的main函数入手,分别调用fun函数,第一个调用中x参数为引用地址,调用后x的值为6,因为参数为地址,所以第二个调用中的x参数值为6,调用后y的计算结果为6。同理, z在第三个函数调用后z的值为6。

  • 第5题:

    阅读以下C++代码,填充(1)~(5)的空缺,将解答填入答题纸的对应栏内。 【说明】在下面程序横线处填上适当的字句,使其输出结果为:x=5x=6y=7x=8z=9【程序】#include<iostream.h>class X1{int x;(1):X1(int xx=0){x=xx;}(2)void Output()(cout<<"x="<<x<<end;}};(3)Y1:public X1{int y;public:Y1(int xx=0,int yy=0):X1(xx){y=yy;}(2)void Output(){(4)Output();cout<<"y="<<y<<end1;}};class Z1:pubtic X1{int z:(5):Z1(int xx=0,int zz=0):X1(xx){z=zz;}②void Output(){X1::Output();cout<<"z="<<z<<end1;}};void main(){X1 a(5);Y1 b(6,7);Z1 c(8,9);X1*p[3]={&a,&b,&c};For(int i=0;i<3;i++){p[i]-->Output();cout<<end1;}}


    答案:
    解析:
    (1)public
    (2)virtual
    (3)class
    (4)X1::
    (5)public
    【解析】

    通过对比三个类的定义就可以发现,在类X1和Z1的定义中缺少类的成员属性声明,而类一般将成员变量声明为公有的、私有的或受保护的三种类型中的一种,在类的定义中,我们一般将类的构造函数放在公有的属性下面,在题目中只能选择公有的属性了,因此,第1空和第5空中应该填“public”。对三个类的定义进行仔细观察后,我们同样可以发现,每个类中都定义了一个同名函数Output(),而且在后两个类的函数体中调用了函数Output(),由此,我们应该想到虚函数。虚函数的作用是允许在派生类中重新定义与基类同名的函数,并且可以通过基类指针或引用来访问基类和派生类中的同名函数。因此,第2空应该填“virtual”。第3空就简单了,考查类的定义,应该填类的标识符“class”。从程序中我们可以看到,类Y1和Z1都以公有的方式继承类X1。从输出的结果来分析,类Y1和Z1都输出了两个数,但单从类Z1的函数来看,只能输出一个变量的值z,因此,可以发现在类Z1中应该和类Y1一样,都调用了类X1的函数Output(),因此,第4空的答案为“X1::”。

  • 第6题:

    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

  • 第7题:

    Given:  1.  public class ConstOver {  2.  public constOver(int x, int y, int z) {  3.  }  4.  }   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、 pubic void ConstOver (byte x, byte y, byte z) {}

    正确答案:A,C

  • 第8题:

    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

  • 第9题:

    多选题
    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;  }


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

  • 第10题:

    多选题
    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) { }


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

  • 第11题:

    单选题
    现有      public class Parentt      public void change (int x){)     )      public class Child extends Parent{     //覆盖父类change方法     }      下列哪个声明是正确的覆盖了父类的change方法?()
    A

      protected void change (int x){}

    B

      public void change(int x,  int y){}

    C

      public void change (int x){}

    D

      public void change (String s){}


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

  • 第12题:

    填空题
    1. public class test {  2. public static string output = “”  3.    4. public static void foo(int i) {  5. try {  6. if(i= =1) {  7. throw new Exception ();  8. }  9. output += “1”;  10.}  11. catch(Exception e)  {  12. output += “2”;  13. return;  14.}  15. finally (  16. output += “3”;  17. )  18. output += “4”;  19. } 20.    21. public static void main (string args[])  (  22. foo(0);  23. foo(1);  24.    25. )  26. } What is the value of the variable output at line 24?()

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

  • 第13题:

    若有以下程序: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。

  • 第14题:

    若有以下程序:include using namespace std;class Base{private: inta,b;public: Bas

    若有以下程序: #include <iostream> using namespace std; class Base { private: int a,b; public: Base(int x, int y) { a=x; b=y; } void disp () { cout<<a<<" "<<b<<end1; } }; class Derived : public Base { private: int c; int d; public: Derived(int x,int y, int z,int m) :Base(x,y) { c=z; d=m; } void disp () { cout<<c<<" "<<d<<end1; } }; int main() { Base b(5,5),*pb; Derived obj(1,2,3,4); pb=&obj; pb->disp(); return 0; } 执行程序后的输出结果是( )。

    A.1,2

    B.3,4

    C.2,3

    D.5,5


    正确答案:A
    解析:本题考核基类指针的使用。本题首先定义了一个基类Base和一个由Base派生出来的派生类Derived。在主函数中,定义了一个基类Base指针pb和基类对象b,还定义了派生类Derived的对象obj。然后将派生类对象obj的地址赋值给指向基类Base的指针pb。由于Derived是Base的子类型,因此允许上述赋值,但这时指针pb只能使用从基类Base继承的成员,即当pb指向obj对象时,pb->disp还是调用基类Base的成员函数disp。所以程序最后输出的对象d中对基类成员的初始化值,即1,2。

  • 第15题:

    若有以下程序: #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()都是公有成员,可以通过对象对它们进行访问。所以程序中对各成员的访问是正确的。本程序的功能是输出已设置的各成员的值。

  • 第16题:

    若有以下程序: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都是公有成员,可以通过对象对它们进行访问。所以程序中对各成员的访问是正确的。本程序的功能是输出已设置的各成员的值。

  • 第17题:

    给定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

  • 第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 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

  • 第20题:

    单选题
    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.


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

  • 第21题:

    单选题
    10. interface A { void x(); }  11. class B implements A { public void x() { } public voidy() { } }  12. class C extends B { public void x() {} }  And:  20. java.util.List list = new java.util.ArrayList();  21. list.add(new B());  22. list.add(new C());  23. for (A a:list) {  24. a.x();  25. a.y();;  26. }  What is the result?()
    A

     The code runs with no output.

    B

     An exception is thrown at runtime.

    C

     Compilation fails because of an error in line 20.

    D

     Compilation fails because of an error in line 21.

    E

     Compilation fails because of an error in line 23.

    F

     Compilation fails because of an error in line 25.


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

  • 第22题:

    多选题
    Given:  1.  public class ConstOver {  2.  public constOver(int x, int y, int z) {  3.  }  4.  }   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

    pubic void ConstOver (byte x, byte y, byte z) {}


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

  • 第23题:

    多选题
    In which two cases does the compiler supply a default constructor for class A?()
    A

    class A{}

    B

    class A { public A(){} }

    C

    class A { public A(int x){} }

    D

    class Z {} class A extends Z { void A(){} }


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

  • 第24题:

    多选题
    给定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){}


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