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

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

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第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){}

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


正确答案:B
解析:该题考查的方法重载。在 Java程序中可以在同一个类中定义多个名称相同的方法,然而这些方法的参数数量和类型却不完全相同,这种现象被成为方法重载。在本题中,选项A是正确的,虽然它的参数的类型和第二行的参数类型相同,但是它的参数数量是不同的;选项B不正确,它的参数类型和参数数量都和第二行的相同;选项C正确,它的参数类型和第二行的参数类型不同;选项D也正确,它的参数类型和数量都不和第二行的相同。

第2题:

类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不符合方法重载的要求。

第3题:

20.publicfloatgetSalary(Employeee){21.assertvalidEmployee(e);22.floatsal=lookupSalary(e);23.assert(sal>0);24.returnsal;25.}26.privateintgetAge(Employeee){27.assertvalidEmployee(e);28.intage=lookupAge(e);29.assert(age>0);30.returnage;31.}Whichlineisaviolationofappropriateuseoftheassertionmechanism?()

A.line21

B.line23

C.line27

D.line29


参考答案:A

第4题:

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

第5题:

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

第6题:

类testl定义如下: public class test1 { public float amethod(float a,float b){ } }

A.public foat amethod(float a,float b,foat c){ }

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

C.public int amethod(int a,int b){ }

D.private float amethod(int a,int b,int c){ }


正确答案:B

第7题:

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

第8题:

Given:11. public void go(int x) {Which statement is true?()

A.All of the assert statements are used appropriately.

B.Only the assert statement on line 12 is used appropriately.

C.Only the assert statement on line 15 is used appropriately.

D.Only the assert statement on line 18 is used appropriately.

E.Only the assert statements on lines 12 and 15 are used appropriately.

F.Only the assert statements on lines 12 and 18 are used appropriately.

G.Only the assert statements on lines 15 and 18 are used appropriately.


参考答案:G

第9题:

类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

第10题:

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

更多相关问题