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

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


相似考题
参考答案和解析
正确答案: D
解析: 暂无解析
更多“单选题20. public float getSalary(Employee e) {  21. assert validEmployee(e);  22. float sal = lookupSalary(e);  23. assert (sal0);  24. return sal;  25. }  26. private int getAge(Employee e) {  27. assert validEmployee(e);  28. int age = lookupAge(e);  29. a”相关问题
  • 第1题:

    类Test定义如下,将下列哪个方法插入③行处是不合法的( )?

    ① public class Test{

    ② public float Method(float a,float B) { }

    ③ ______

    ④ }

    A.public float Method(float a,float b,float C) { }

    B.public float Method(float c,float d){ }

    C.public int Method(int a,int B) { }private float Method(int a,int b,int C) { }

    D.private float Method(int a,int b,int C) { }


    正确答案:B
    解析:本题主要考查方法重载,方法的重载是指多个方法可以享有相同的名字,但参数的数量或类型必须不相同(采用不同的形式参数列表),选项B不符合方法重载的要求。

  • 第2题:

    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

  • 第3题:

    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

  • 第4题:

    11. class Payload {  12. private int weight;  13. public Payload(int wt) { weight = wt; }  13. public void setWeight(mt w) { weight = w; }  15. public String toString { return Integer.toString(weight); }  16. }  17.  18. public class TestPayload {  19. static void changePayload(Payload p) { 20. /* insert code here */ 21. }  22.  23. public static void main(String[] args) {  24. Payload p = new Payload();  25. p.setWeight(1024);  26. changePayload(p);  27. System.out.println(”The value of p is “+ p);  28. }  29. }  Which statement, placed at line 20, causes the code to print “The value of p is 420.”?() 

    • A、 p.setWeight(420);
    • B、 p.changePayload(420);
    • C、 p = new Payload(420);
    • D、 Payload.setWeight(420);
    • E、 p = Payload.setWeight(420);
    • F、 p = new Payload(); p.setWeight(420);

    正确答案:A

  • 第5题:

    public class MethodOver  {  public void setVar (int a, int b, float c)  {  }  }   Which two overload the setVar method?()  

    • A、 Private void setVar (int a, float c, int b)  { }
    • B、 Protected void setVar (int a, int b, float c) { }
    • C、 Public int setVar (int a, float c, int b) (return a;)
    • D、 Public int setVar (int a, int b, float c) (return a;)
    • E、 Protected float setVar (int a, int b, float c) (return c;)

    正确答案:A,C

  • 第6题:

    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

  • 第7题:

    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

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


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

  • 第9题:

    单选题
    下列选项中,能实现对父类的getSalary方法重写的是(  )。 class Employee{ public double getSalary(){} }
    A

    class Manager extends Employee{
    public int getSalary(double x){}
    }

    B

    class Manager extends Employee{
    public double getSalary(int x,int y){}
    }

    C

    class Manager extends Employee{
    public double getSalary(){}
    }

    D

    class Manager extends Employee{
    public int getSalary(int x,int y){}
    }


    正确答案: A
    解析: 对一个类的继承是指在现有类(父类)的基础上构建一个新类(子类),子类重用(继承)了父类的方法和属性(该属性和方法不能被private修饰),同时还可以向新类中增添新的方法的状态。所以,在子类中可以进行的操作是添加方法。但是不能减少或更换父类的方法。在对父类的方法进行重写的时候,方法的返回值、返回值类型、参数个数、相应的参数类型都要一一对应,所以对父类的getSalary方法重写的时候,返回值的类型应该是double,没有参数。

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

    单选题
    11. class Payload {  12. private int weight;  13. public Payload(int wt) { weight = wt; }  13. public void setWeight(mt w) { weight = w; }  15. public String toString { return Integer.toString(weight); }  16. }  17.  18. public class TestPayload {  19. static void changePayload(Payload p) { 20. /* insert code here */ 21. }  22.  23. public static void main(String[] args) {  24. Payload p = new Payload();  25. p.setWeight(1024);  26. changePayload(p);  27. System.out.println(”The value of p is “+ p);  28. }  29. }  Which statement, placed at line 20, causes the code to print “The value of p is 420.”?()
    A

     p.setWeight(420);

    B

     p.changePayload(420);

    C

     p = new Payload(420);

    D

     Payload.setWeight(420);

    E

     p = Payload.setWeight(420);

    F

     p = new Payload(); p.setWeight(420);


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

  • 第12题:

    单选题
    11. public class Test {  12. public void foo() {  13. assert false;  14. assert false;  15. }  16. public void bar(){  17. while(true){  18. assert false;  19. }  20. assert false;  21. }  22. }  What causes compilation to fail?()
    A

     Line 13

    B

     Line 14

    C

     Line 18

    D

     Line 20


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

  • 第13题:

    Given:  1. public class Method Over {  2. public void set Var (int a, int b, float c) {  3. }  4. }   Which two overload the set Var method()?

    • A、 private void set Var(int a, float c, int b) {}
    • B、 protected void set Var(int a, int b, float c) {}
    • C、 public int set Var(int a, float c, int b) {return a:}
    • D、 public int set Var(int a, int b, float c) {return a:}
    • E、 protected float set Var(int a, int b, float c) {return c:}

    正确答案:A,C

  • 第14题:

    类Test1定义如下: 1.public class Test1{ 2. public float aMethod(float a,float b){ return 0;} 3. 4.} 将以下哪种方法插入行3是不合法的。()

    • A、public float aMethod(float a, float b,float c){ return 0;}
    • B、public float aMethod(float c,float d){ return 0;}
    • C、public int aMethod(int a, int b){ return 0;}
    • D、private float aMethod(int a,int b,int c){ return 0;}

    正确答案:B

  • 第15题:

    11. public class Test {  12. public void foo() {  13. assert false;  14. assert false;  15. }  16. public void bar(){  17. while(true){  18. assert false;  19. }  20. assert false;  21. }  22. }  What causes compilation to fail?()  

    • A、 Line 13
    • B、 Line 14
    • C、 Line 18
    • D、 Line 20

    正确答案:D

  • 第16题:

    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

  • 第17题:

    11. class Person {  12. String name = “No name‟;  13. public Person(String nm) { name = nm; }  14. }  15.  16. class Employee extends Person {  17. String emplD = “0000”;  18. public Employee(String id) { empID = id; }  19. }  20.  21. public class EmployeeTest {  22. public static void main(String[] args) {  23. Employee e = new Employee(”4321”);  24. System.out.println(e.empID);  25. }  26. }  What is the result?() 

    • A、 4321
    • B、 0000
    • C、 An exception is thrown at runtime.
    • D、 Compilation fails because of an error in line 18.

    正确答案:D

  • 第18题:

    10. interface Foo {  11. int bar();  12. }  13.  14. public class Beta {  15.  16. class A implements Foo {  17. public int bar() { return 1; }  18. }  19.  20. public int fubar( Foo foo) { return foo.bar(); }  21.  22. public void testFoo() {  23.  24. class A implements Foo {  25. public int bar() { return 2; }  26. }  27.  28. System.out.println( fubar( new A())); 29. }  30.  31. public static void main( String[] argv) {  32. new Beta().testFoo();  33. }  34. }  Which three statements are true?()

    • A、 Compilation fails.
    • B、 The code compiles and the output is 2.
    • C、 If lines 16, 17 and 18 were removed, compilation would fail.
    • D、 If lines 24, 25 and 26 were removed, compilation would fail.
    • E、 If lines 16, 17 and 18 were removed, the code would compile and the output would be 2.
    • F、 If lines 24, 25 and 26 were removed, the code would compile and the output would be 1.

    正确答案:B,E,F

  • 第19题:

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

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

    B

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

    C

    Public int setVar (int a, float c, int b) (return a;)

    D

    Public int setVar (int a, int b, float c) (return a;)

    E

    Protected float setVar (int a, int b, float c) (return c;)


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

  • 第20题:

    单选题
    11. class Person {  12. String name = “No name‟;  13. public Person(String nm) { name = nm; }  14. }  15.  16. class Employee extends Person {  17. String emplD = “0000”;  18. public Employee(String id) { empID = id; }  19. }  20.  21. public class EmployeeTest {  22. public static void main(String[] args) {  23. Employee e = new Employee(”4321”);  24. System.out.println(e.empID);  25. }  26. }  What is the result?()
    A

     4321

    B

     0000

    C

     An exception is thrown at runtime.

    D

     Compilation fails because of an error in line 18.


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

  • 第21题:

    单选题
    类Test1定义如下: 1.public class Test1{ 2. public float aMethod(float a,float b){ return 0;} 3. 4.} 将以下哪种方法插入行3是不合法的。()
    A

    public float aMethod(float a, float b,float c){ return 0;}

    B

    public float aMethod(float c,float d){ return 0;}

    C

    public int aMethod(int a, int b){ return 0;}

    D

    private float aMethod(int a,int b,int c){ return 0;}


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

  • 第22题:

    多选题
    10. interface Foo {  11. int bar();  12. }  13.  14. public class Beta {  15.  16. class A implements Foo {  17. public int bar() { return 1; }  18. }  19.  20. public int fubar( Foo foo) { return foo.bar(); }  21.  22. public void testFoo() {  23.  24. class A implements Foo {  25. public int bar() { return 2; }  26. }  27.  28. System.out.println( fubar( new A())); 29. }  30.  31. public static void main( String[] argv) {  32. new Beta().testFoo();  33. }  34. }  Which three statements are true?()
    A

    Compilation fails.

    B

    The code compiles and the output is 2.

    C

    If lines 16, 17 and 18 were removed, compilation would fail.

    D

    If lines 24, 25 and 26 were removed, compilation would fail.

    E

    If lines 16, 17 and 18 were removed, the code would compile and the output would be 2.

    F

    If lines 24, 25 and 26 were removed, the code would compile and the output would be 1.


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

  • 第23题:

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


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

  • 第24题:

    单选题
    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
    解析: 暂无解析