- 1、本文档共36页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
java-sun试题2
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 appropriately
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
断言应该用在“你认为”你的程序不可能产生错误的地方,而且有没有启用断言,都不会影响程序的正常运行。
断言使用限制:
不要在public方法中,用断言来检查参数的正确性;
不要让断言语句去处理一些程序必须的流程。
原因:1.public方法会被别人调用,你不能保证他一定启用断言;如果没有启用,那么用断言来做参数的检查也就没有意义了。所以不要用断言来检查参数,公共方法的参数要执行断言语句不可以有任何边界效应,不要使用断言语句去修改变量和改变方法的返回值 断言语句不是永远会执行,可以屏蔽也可以启用 –source 1.4 *.java
需要java –ea 启用assert; 当判断条件为FALSE时就抛出错误。
Answer: ( C )
26行不合适:不要对public方法的参数断言29合适:在程序最不大可能到达的地方断言?31合适:断言private方法的参数?33行不合适:参考大纲:异常处理 — 断言和AssertionError
QUESTION 62
GIVEN THE EXHIBIT:
What is the result?
A. null
B. zero
C. some
D. Compilation fails
E. An exception is thrown at runtime
Answer: ( 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 Exception;
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 runtime
Answer: ( 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. Compilation fails.
G. An exception is thrown at
文档评论(0)