




已阅读5页,还剩31页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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断言应该用在“你认为”你的程序不可能产生错误的地方,而且有没有启用断言,都不会影响程序的正常运行。 断言使用限制:1. 不要在public方法中,用断言来检查参数的正确性;2. 不要让断言语句去处理一些程序必须的流程。原因:1.public方法会被别人调用,你不能保证他一定启用断言;如果没有启用,那么用断言来做参数的检查也就没有意义了。所以不要用断言来检查参数,公共方法的参数一定要用代码执行检查;2.如果用断言来控制程序执行流程,如果没有启用断言, 那么程序就不能正确执行下去。另外,断言语句不可以有任何边界效应,不要使用断言语句去修改变量和改变方法的返回值 ,如果这样当启动断言和不启动断言执行的结果会截然不同。断言的使用时机:1. 检查流程的不变性:在if-else switch-case 的预期结果之外可以加上断言做额外的检查。2. 内部执行的不变性:if(true)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: 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 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 runtimeAnswer: ( 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 runtime Answer: ( D )Set中存放的元素是无序不重复的。如果你想Set里Add一个元素,首先他会去调用equals方法,判断set中是否有该元素,如果有则不更改set的值并返回false,如果没有,则把元素添加进去,并返回true。Ws1 ws2是自定义的类,ws1 和 ws2 equals不相等;String的equals方法已经改写,s1和s2相等;比较两个对象是否相同,先比较hashcode, 如果相同,在用equals方法比较.如果都相同则两个对象就认为是相同的.Hashcode是把对象的内存地址经过运算得来的.基本数据类型和基本数据类型的包装类还有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 ( ); 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 : 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 order.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: ( )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: Results 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取第一个元素,并不删除元素QUESTION 71Given: A programmer is developing a class Key, that will be used as a key in a standard java.util.HashMap. Which two methods should be overridden to assure that key works correctly as a key? (choose two) A. public int hashCode ( ) B. public Boolean equals (Key k) C. public int compareTo (Object o) D. public Boolean equals (Object o) Answer: ( A, D )HashMap中的key不能重复,因此必须实现hashCode和equals方法QUESTION 72 -Given the exhibit: Which two, inserted at line 2 will allow the code to compile? (Choose Two) A. public class MinMax B. public class MinMax C. public class MinMax D. public class MinMax E. public class MinMax F. public class MinMax Answer: ( D, F )N是泛型类别变量,它相当于一个类型。A类声明是不能用?这个万用字符。B同上CObject没有doubleValue()方法。DOK.E同A。FOK.QUESTION 73Given the exhibit: enum Example ONE, TWO, THREE Which statement is true? A. The expressions (ONE = = ONE) and ONE.equals (ONE) are both guaranteed to be true. B. The expression (ONE TWO ) is guaranteed to be true and ONE.compareTo (TWO) is guaranteed to be less than one. C. The Example values cannot be used in a raw java.util.HashMap.; instead, the programmer must use a java.util.EnumMap. D. The Example values can be used in a java.util.SortedSet, but the set will NOT be sorted because enumerated Type do NOT IMPLEMENT java.lang.Comparable. Answer: ( A )A 正确B 不能保证C 错误 枚举类型的元素是可以用在HASHMAP里的HashMaph = new HashMap;h.put(1, Example.ONE);D 错误,枚举类型的元素值是可以放入SortedSet里的例如TreeSet. 把枚举类型的元素转成字符串在放入其中,字符串就已经实现comparable接口。可以自然排序。SortedSet s = new TreeSet();s.add(Example.TWO);s.add(Example.ONE);System.out.println(s);打印出结果ONE, TWOQUESTION 74Given the exhibit: Which line of code marks the earliest point that an object referenced by intObj becomes a candidate for garbage collection? A. Line 16 B. Line 17 C. Line 18 D. Line 19 E. The object is NOT a candidate for garbage collection.Answer: ( D )intObj一直会被numbers引用,直到19行之后QUESTION 75Given: And the command line invocation: javaYippee2 a b c What is the result? A. a b B. b c C. a b c D. Compilation fails. E. An exception is thrown at runtime.Answer: ( B )QUESTION 76A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wants to execute the main method of Poker on a UNIX system using the command: Java games.cards.Poker What allows the user to do this? A. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java B. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/*.jarC. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/Poker.jar D. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java E. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/*.jar F. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/Poker.jarAnswer: ( C )classpath中须明确写明poker.jar,不能用*.jarQUESTION 77Which three code fragments, added individually at line 29, produce the output 100? (Choose three.) A. n = 100; B. i.setX(100); C. o.getY().setX( 100 ); D. i = new Inner(); i.setX( 100 ); E. 0.setY ( i ); i = new Inner(); i.setX ( 100 ); F. i = new Inner (); i.setX( 100 ); o.setY( i ); Answer: ( B, C, F )根据内存关系可知QUESTION 78Given a class Repetition: And given another class Demo: Which code should be inserted at line 1 of Demo.java to compile and run Demo to print pizzapizza A. import utils.*; B. static import utils.*; C. import utils.Repetition.*; D. static import utils.Repetition.*; E. import utils.Repetition.twice(); F. import static utils.Repetition.twice; G. static import utils.Repetition.twice;Answer: ( F )静态import引入静态方法. import static utils.Repetition*; 或者 import static utils.Repetition.twice;A正常的导入类,Demo的第5行要new实例才能带用twice方法.Bstatic import 顺序颠倒,而且要加上class名C正常的导入,类名后面不能跟*D顺序颠倒E正常的导入,只能导入包下的类,不能导入类里的方法.G顺序颠倒QUESTION 79Given: And the invocation: What is the result? A. An exception is thrown at runtime. B. String is empty is printed to output. C. Compilation fails because of an error in line 12. D. String is not empty is printed to output.Answer: ( A )A空指针异常-“|”是非短路逻辑运算符QUESTION 80Exhibit: Given the fully-qualified class names: com.foo.bar.Dog com.foo.bar.blatz.Book com.bar.Car com.bar.blatz.Sun Which graph represents the correct directory structure for a JAR file from which those classes can be used by the compiler and JVM? A. Jar A B. Jar B C. Jar C D. Jar D E. Jar EAnswer: ( A )QUESTION 81Given: and two separate command line invocations: java Yippee java Yippee 1 2 3 4 What is the result? A. No output is produced. 1 2 3 B. No output is produced. 2 3 4 C. No output is produced. 1 2 3 4 D. An exception is thrown at runtime. 1 2 3 E. An exception is thrown at runtime. 2 3 4 F. An exception is thrown at runtime. 1 2 3 4Answer: ( B )QUESTION 82Given: What is the result? A. Compilation fails B. An exception is thrown at runtime C. doStuff x = 6 main x = 6 D. doStuff x = 5 main x = 5 E. doStuff x = 5 main x = 6 F. doStuff x = 6 main x = 5Answer: ( D )第10行参数x是值传递,不会改变main中x的值。QUESTION 83Given:When the doSomething method is called, after which line does the Object created in line 5 become available for garbage collection? A. Line 5 B. Line 6 C. Line 7 D. Line 8 E. Line 9 F. Line 10Answer: ( D )栈内存用来存放基本类型的变量和对象的引用变量(对象的地址)堆内存用来存放由new创建的对象和数组QUESTION 84Given: What is the result? A.Exception B. A, B, Exception C. Compilation fails because of an error in line 20. D. Compilation fails because of an error in line 14. E. A NullPointerException is thrown at runtime.Answer: ( D ) 改写的规定,子类抛出的异常要比父类的异常要小.本题中父类没有异常,子类也不能有异常.QUESTION 85Given:What is the result? A. harrier B. shepherd C. retriever D. Compilation fails E. retriever harrier F. An exception is thrown at runtime. Answer: ( D )18行,case default: 语法错误,应改成default:QUESTION 86Given: What is the result? A. A, B, C B.B, C, A C.Compilation fails D. The code runs with no output E. An exception is thrown at runtimeAnswer: ( B )LinkedList有顺序性, QUESTION 87GivenWhat is the result? A. end B. Compilation fails C. exception end D. exception test end E. A Throwable is thrown by main F. An Exception is thrown by mainAnswer: ( E )16行抛出Error, 没有捕获。 Throwable, Error 和Exception都是他的子类QUESTION 88Given: Which three, will make code on 37 executeA. The instance gets garbage collected. B. The code on line 33 throws an exception. C. The code on line 35 throws an exception. D. The code on line 31 throws an exception. E. The code on line 33 executes successfully.Answer: ( B, C , E)QUESTION 89Given:What is the result? A. Compilation fails B. pi is bigger than 3. C. An exception occurs at runtime. D. pi is bigger than 3. Have a nice day. E. pi is not bigger than 3. Have a nice day. Answer: ( A )18行finally 是配合try使用的.QUESTION 90Given: Which code, inserted at line 16 will cause a java.lang.ClassCastException? A. Alpha a = x; B. Foo f = (Delta)x; C. Foo f = (Alpha)x; D. Beta b = (Beta)(Alpha)x;Answer: ( B )转到子类别抛异常。.QUESTION 91Given a method that must ensure that its parameter is not null: What, inserted at line 12, is the appropriate way to handle a null value? A. assert value = = null; B. assert value != null, value is null; C. if (value = = null) throw new AssertionException(value is null); D. if (value = = null) throw new IllegalArgumentException(value is null); Answer: ( D )A不要用断言对公共方法的参数进行判断B同上C 没有AssertionException这个类; AssertionError继承自Error,handle error是没有意义的DOK 抛出参数错误的异常.QUESTION 92Place the correct Code in the Code Sample to achieve the expected results. Expected results: Output: 1 2 4 8 16 32 Code Sample Answer: ( )for (int x : y)QUESTION 93Given: Which two will produce an AssertionError? (Choose two.) A. java test B. java -ea test C. java test file1 D. java -ea test file1 E. java -ea test file1 file2 F. java ea : test test file1 Answer: ( B, E )QUESTION 94Given: Which statement is true if a ResourceException is thrown on line 86? A. Line 92 will not execute. B. The connection will not be retrieved in line 85. C. The resource connection will not be closed on line 88. D. The enclosing method will throw an exception to its caller.Answer: ( C )QUESTION 95Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given: What is the result? A. restore 400 B. restore 403 C. restore 453 D. Compilation fails. E. An exception is thrown at runtime.Answer: ( C )QUESTION 96Given: What is the result? A. Compilation fails B. Pi is approximately 3. C. Pi is approximately 3.141593. D. An exception is thrown at runtime. Answer: ( D )%d打印一个整数,要求接受一个整数 抛IllegalFormatConversionExceptionQUESTION 97Given: What is the result?A. int Long B. Short Long C. Compilation fails D. An exception is thrown at runtime.Answer: ( A )QUESTION 98Chain these constructors to create objects to read from a file named in and to write to a file named out.Answer: ( )new BufferedReader( new FileReader( “in”);new PrintWriter( new BufferedWriter( new FileWriter( “out”);QUESTION 99Place the code fragments into position to use a BufferedReader to read in an entire text file.Answer: ( )class PrintFilepublic static void main(String args)BufferedReader buffReader = null;/more code here to initialize buffReadertryString temp;while(temp=buffReader.readLine() !=null)System.out.println(temp);catch (IOException e)e.printStackTrace();QUESTION 100Given this method in a class: Which statement is true? A. This code is NOT thread-safe. B. The programmer can replace StringBuffer with StringBuilder with no other changes. C. This code will perform poorly. For better performance, the code should be rewritten: return ; D. This code will perform well and converting the code to use StringBuilder will not enhance the performance.Answer: ( B )QUESTION 101Given: What creates the appropriate DateFormat object and adds a day to the Date object? A. 35. Dateformat df = Dateformat.getDateFormat(); 42. d.setTime ( (60 * 60 * 24) + d.getTime(); B.35. Dateformat df = Dateformat.getDateInstance(); 42. d.setTime ( (1000 * 60 * 60 * 24) + d.getTime(); C.35. Dateformat df = Dateformat.getDateFormat(); 42. d.setLocalTime ( (1000 * 60 * 60 * 24) + d.getLocalTime(); D. 35. Dateformat df = Dateformat.getDateInstance(); 42. d.setLocalTime ( (60 * 60 * 24) + d.getLocalTime();Answer: ( B )转换成求加1天以后改日期的毫秒数,再调用setTime()设置时间QUESTION 102Given: Which two statements are true about the result if the locale is Locale.US? (Choose two.) A. The value of b is 2. B. The value of a is 3.14. C. The value of b is 2.00. D. The value of a is 3.141. E. The value of a is 3.1415. F. The value of a is 3.1416. G. The value of b is 2.0000.Answer: ( C, F )QUESTION 103Place the correct description of the compiler output on the code fragment to be inserted at line 4 and 5. The same compiler output may be used more than once.Answer: ( )QUESTION 104Given: Which three will compile successfully? (Choose three.) A. Object o = Old.get0(new LinkedList(); B. Object o = Old.get0(new LinkedList(); C. String s = Old.get0(new LinkedList(); D. Object o = Old.get0(new LinkedList();E. String s = (String)Old.get0(new LinkedList();Answer: ( A, D, E )B 错误 不应出现在这里C 错误 get0()方法的回传值是Object, 因此不可赋值给StringQUESTION 105Exhibit: Which statement is true about the set variable on line 12? A. The set variable contains all six elements from the coll collection, and the order is guaranteed to be preserved. B. The set variable contains only three elements from the coll collection, and the order is guaranteed to be preserved. C. The set variable contains all six elements from the coll collection,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年国际经济贸易领域招聘面试预测题与解析大全
- 2025年制造业生产管理岗位竞聘面试模拟题与实战技巧
- 2025年微纤维玻璃棉项目发展计划
- 抽油机基础知识培训
- 2025年公寓式酒店项目合作计划书
- 2025年VXI总线各类卡式仪器项目合作计划书
- 2025年光电器件用低温封接玻璃合作协议书
- 2025-2026学年北师大版(2024)小学数学三年级上册《里程表》教学设计
- 2025年拉杆球头项目合作计划书
- 抗酸染色课件
- 2025店面劳动合同范本:超市收银员专项协议
- 展会联合承办协议书范本
- 2025设备担保抵押借款合同
- 早教托育合伙人合同协议
- 2025年舞蹈培训学校工作计划及方案范文
- 2025至2030年中国视频监控系统行业市场运行态势及投资战略研究报告
- GB/T 45953-2025供应链安全管理体系规范
- 2025陕西寰宇正信科技产业发展有限公司招聘(71人)笔试参考题库附答案解析
- 污水处理设施运行维护手册与规范
- AIGC艺术设计 课件 第8章 AIGC艺术设计的思考与展望
- 物业财务基础知识培训课件
评论
0/150
提交评论