2024年SCJP认证考试题库

上传人:m**** 文档编号:569071256 上传时间:2024-03-19 格式:DOC 页数:59 大小:3.01MB
返回 下载 相关 举报
2024年SCJP认证考试题库_第1页
第1页 / 共59页
2024年SCJP认证考试题库_第2页
第2页 / 共59页
2024年SCJP认证考试题库_第3页
第3页 / 共59页
2024年SCJP认证考试题库_第4页
第4页 / 共59页
2024年SCJP认证考试题库_第5页
第5页 / 共59页
点击查看更多>>
资源描述

《2024年SCJP认证考试题库》由会员分享,可在线阅读,更多相关《2024年SCJP认证考试题库(59页珍藏版)》请在金锄头文库上搜索。

1、QUESTION 61 GIVEN THE EXHIBIT: Which statement 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 approp

2、riately E. The assert statements on lines 29 and 33 are used appropriately F. The assert statements on lines 29 ,31and 33 are used appropriately G. The assert statements on lines 26,29 and 31 are used appropriately断言应当用在“你以为”你的程序不也许产生错误的地方,并且有无启用断言,都不会影响程序的正常运行。 断言使用限制:1. 不要在public措施中,用断言来检查参数的正确性;2

3、. 不要让断言语句去处理某些程序必须的流程。原因:1.public措施会被他人调用,你不能确保他一定启用断言;假如没有启用,那么用断言来做参数的检查也就没故意义了。因此不要用断言来检查参数,公共措施的参数一定要用代码执行检查;2.假如用断言来控制程序执行流程,假如没有启用断言, 那么程序就不能正确执行下去。另外,断言语句不能够有任何边界效应,不要使用断言语句去修变化量和变化措施的返回值 ,假如这么当开启断言和不开启断言执行的成果会截然不一样。断言的使用时机:1. 检查流程的不变性:在if-else switch-case 的预期成果之外能够加上断言做额外的检查。2. 内部执行的不变性:if(t

4、rue)return ; assert false;3. 检查 私有措施的参数,成果等4. 程序运行中的一致性 断言语句不是永远会执行,能够屏蔽也能够启用 javac source 1.4 *.java需要java ea 启用assert; 当判断条件为FALSE时就抛犯错误。Answer: ( C )26行不宜:不要对public措施的参数断言29适宜:程序员在程序中最不大也许抵达的地方断言31适宜:断言private措施的参数33行不宜:启用和不启用断言会产生不一样的程序执行序参考大纲:异常处理 断言和AssertionErrorQUESTION 62 GIVEN THE EXHIBIT:

5、 What is the result?A.nullB.zero C.some D.Compilation fails E.An exception is thrown at runtimeAnswer: ( D )13行会报错,应在15行使用else if参考大纲:流程控制QUESTION 63 Given the exhibit: What is the result? A. test B. Exception C. Compilation fails D. NullPointerException Answer: ( C ) 18行犯错,应当先catch子异常,再catch Except

6、ion; 13行把args赋null ,14行会报NullPointerException假如没有第13行运行时14行会报ArrayIndexOutOfBoundsException异常。参考大纲:异常处理QUESTION 64 Given the exhibit: What is the result?A. Compilation fails B. aAaA aAa AAaa AaA C. AAaa AaA aAa aAaA D. AaA AAaa aAaA aAa E. aAa AaA aAaA AAaa F. An exception is thrown at runtimeAnswer

7、: ( C )第10行将对strings这个集合做自然排序(ASCII小到大,一个一个比较)Collections.sort(List list) 对list进行排序,对set不能排序!List里能够放对象,因此当list里面存储的是对象的时候就不能用Collections.sort(List list)去排序了。因为JVM不懂得用什么规则去排序!只有把对象类实现Comparable接口,然后改写compareTo()参考大纲:集合QUESTION 65 Given the exhibit: What is the result? A. 0 B. 1 C. 2 D. 3 E. 4 F. Com

8、pilation fails. G. An exception is thrown at runtime Answer: ( D )Set中存储的元素是无序不重复的。假如你想Set里Add一个元素,首先他会去调用equals措施,判断set中是否有该元素,假如有则不更改set的值并返回false,假如没有,则把元素添加进去,并返回true。Ws1 ws2是自定义的类,ws1 和 ws2 equals不相等;String的equals措施已经改写,s1和s2相等;比较两个对象是否相同,先比较hashcode, 假如相同,在用equals措施比较.假如都相同则两个对象就以为是相同的.Hashcod

9、e是把对象的内存地址通过运算得来的.基本数据类型和基本数据类型的包装类尚有String类都已经覆盖了hashcode(), equals(),因此这些对象的值只要同样就以为对象同样.参考大纲:集合QUESTION 66Given a pre-generics implementation of a method: Which three changes must be made to the method sum to use generics? (choose three) A. remove line 14 B. replace line 14 with int i = iter.next

10、 ( ); C. replace line 13 with for ( int i : intList ) D. replace line 13 with for (Iterator iter : intList ) E. replace the method declaration with sum (List intList) F. replace the method declaration with sum ( List intList)Answer: ( A, C, F )public static int sum(List intList)int sum=0;for(int i :

11、 intList)sum += i;return sum;参考大纲:集合和泛型What is the result? A. Compilation fails due to an error in line 23. B. Compilation fails due to an error in line 29. C. A ClassCastExceptation occurs in line 29. D. A ClassCastExceptation occurs in line 31. E. The value of all four object prints in natural ord

12、er.Answer: ( C ) Arrays.sort(Object a)措施中,a的每一个元素都必须是相互能够比较的(调用pareTo(Object o2) )。否则会报ClassCastException的异常。参考大纲:泛型QUESTION 68 Place the code into position to create a class that maps from Strings to Integer values. The result of execution must be one. Some options may be used more than once.Answer

13、: ( )public class NumberNames private HashMap map = new HashMap();public void put(String name, Integer value)map.put(name, value);public Set getNames()Return map.keySet();QUESTION 69Place a result onto each method call to indicate what would happen if the method call were inserted at line 9. Note: R

14、esults can be used more than once.Answer: ( )MethodResultm1(listA)Compiles and runs without error泛型规范没问题m2(listA)Compiles and runs without error泛型规范没问题m1(listB)Compiles and runs without errorB是A的子类,泛型规范没问题m2(listB)Does not compilem1(listO)Does not compilem2(listO)Does not compileQUESTION 70Given the exhibit:What is the result? A. apple:apple B. carrot:apple C. apple:banana D. banana:apple E. carrot:carrot F. carrot:bananaAnswer: ( C )PriorityQueue优先级队列:预设是自然排序,因此pq内的元素次序将是apple-banana-carrotpoll()取第一个元素,取完之后删除,peek取第一个元素,并不删除元素Q

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 习题/试题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号