【计算机类职业资格】计算机Java认证-2及答案解析.doc
《【计算机类职业资格】计算机Java认证-2及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】计算机Java认证-2及答案解析.doc(37页珍藏版)》请在麦多课文档分享上搜索。
1、计算机 Java认证-2 及答案解析(总分:100.00,做题时间:90 分钟)一、不定项选择题(总题数:42,分数:100.00)1.Given: 1. public class Endless 2. public static void main(String args) 3. int i = 0; 4. short s = 0; 5. for(int j = 0, k = 0; j 3; j+); 6. for(int j = 0; j 3; counter(j); 7. for(int j = 0, int k = 0; j 3; j+); 8. for(; i 5; counter(
2、5), i+); 9. for(i = 0; i 3; i+, System.out.print(“howdy “); 10. 11. static int counter(int y) return y + i; 12. What is the result? (Choose all that apply.)(分数:2.50)A.howdy howdy howdyB.The code runs in an endless loop.C.Compilation fails due to an error on line 5.D.Compilation fails due to an error
3、 on line 6.E.Compilation fails due to an error on line 7.F.Compilation fails due to an error on line 8.G.Compilation fails due to an error on line 9.2.Given: 2. class Big 3. void doStuff(int x) 4. 5. class Heavy extends Big 6. / void doStuff(byte b) 7. / protected void doStuff(int x) throws Exceptio
4、n 8. 9. public class Weighty extends Heavy 10. / void doStuff(int x) 11. / String doStuff(int x) return “hi“; 12. / public int doStuff(int x) return 7; 13. / private int doStuff(char c) throws Error return 1; 14. Which method(s), ifuncommented independently, compile? (Choose all that apply.)(分数:2.50
5、)A.Line 6B.Line 7C.Line 10D.Line 11E.Line 12F.Line 133.Which are true? (Choose all that apply.)(分数:2.50)A.A given TreeSet“s ordering cannot be changed once it“s created.B.The java.util.Properties class is conceptually more like a List than like a Map.C.It“s a reasonable design choice to use a Linked
6、List when you want to design queue-like functionality.D.Of the main types of collections flavors (Lists, Sets, Maps), Queues are conceptually most like Sets.E.It“s programmatically easier to perform a non-destructive traversal of a PriorityQueue than a LinkedList.F.Classes that implement the Set int
7、erface are usually well suited for applications that require access to a collection based on an index.4.Given the following directory structure: test -| |- Finder.class |- testdir -| |- subdir |- subdir2 |- testfile.txt If test, testdir, subdir, and subdir2 are all directories, and Finder.class and
8、testfile.txt are files, and given: import java.io.*; public class Finder public static void main(String args) throws IOException String files = new String100; File dir = new File(args0); files = dir.list(); System. out.println (files.length); And, if the code compiles, the invocation: java Finder te
9、stdir What is the result?(分数:2.50)A.1B.2C.3D.4E.5F.100G.Compilation fails.H.An exception is thrown at runtime.5.Given: 1. public class Grids 2. public static void main(String args) 3. int ia2; 4. int ia1 = 1,2,3; 5. Object o = ia1; 6. ia2 = new int3 3 ; 7. ia20 = (int)o; 8. ia20 0 = (int)o; 9. What
10、is the result? (Choose all that apply.)(分数:2.50)A.Compilation fails due to an error on line 4.B.Compilation fails due to an error on line 5.C.Compilation fails due to an error on line 6.D.Compilation fails due to an error on line 7.E.Compilation fails due to an error on line 8.F.Compilation succeeds
11、 and the code runs without exception.G.Compilation succeeds and an exception is thrown at runtime.6.Given: 3. public class OffRamp 4. public static void main(String args) 5. int exits = 0,0,0,0,0,0; 6. int x1 = 0; 7. 8. for(int x = 0; x 4; x+) exits0 = x; 9. for(int x = 0; x 4; +x) exits1 = x; 10. 1
12、1. x1 = 0; while(x1+ 3) exits2 = x1; 12. x1 = 0; while(+x1 3) exits3 = x1; 13. 14. x1 = 0; do exits4 = x1; while(x1+ 7); 15. x1 = 0; do exits5 = x1; while(+x1 7); 16. 17. for(int x: exits) 18. System.out.print(x + “ “); 19. What is the result?(分数:2.50)A.3 3 2 2 6 6B.3 3 3 2 7 6C.3 3 3 2 7 7D.4 3 3 2
13、 7 6E.4 3 3 2 7 7F.Compilation fails.7.Given: 2. import java.util.*; 3. public class HR 4. public static void main(String args) 5. ListInteger i = new VectorInteger(); 6. i.add(3); i.add(2); i.add(5); 7. int ref = 1; 8. doStuff (ref); 9. System.out.println(i.get(ref); 10. 11. static int doStuff(int
14、x) 12. return +x; 13. What is the result?(分数:2.50)A.2B.3C.5D.Compilation fails.E.An exception is thrown at runtime.8.Given: 2. import java.util.*; 3. public class Vinegar 4. public static void main(String args) 5. SetInteger mySet = new HashSetInteger(); 6. do1 (mySet, “0“); do1 (mySet, “a“); 7. do2
15、 (mySet, “0“); do2 (mySet, “a“); 8. 9. public static void do1 (Set s, String st) 10. s.add (st); 11. s.add(Integer.parseInt (st); 12. 13. public static void do2(SetInteger s, String st) 14. s.add (st); 15. s.add(Integer.parseInt (st); 16. Which are true? (Choose all that apply.)(分数:2.50)A.Compilatio
16、n succeeds.B.Compilation fails due to an error on line 6.C.Compilation fails due to an error on line 13.D.Compilation fails due to an error on line 14.E.Compilation fails due to an error on line 15.F.If only the line(s) of code that don“t compile are removed, the code will run without exception.G.If
17、 only the line(s) of code that don“t compile are removed, the code will throw an exception.9.Given: 3. class Employee 4. private String name; 5. void setName(String n) name = n; 6. String getName() return name; 7. 8. interface Mungeable 9. void doMunging(); 10. 11. public class MyApp implements Mung
18、eable 12. public void doMunging() ; 13. public static void main(String args) 14. Employee e = new Employee(); 15. e.setName (“bob“); 16. System.out.print (e.getName(); 17. Which are true? (Choose all that apply.)(分数:2.50)A.MyApp is-a Employee.B.MyApp is-a Mungeable.C.MyApp has-a Employee.D.MyApp has
19、-a Mungeable.E.The code is loosely coupled.F.The Employee class is well encapsulated.10.Given that FileNotFoundException extends IOException, and given: 2. import java.io.*; 3. public class MacPro extends Laptop 4. public static void main(String args) 5. new MacPro() .crunch(); 6. 7. / insert code h
20、ere 8. 9. class Laptop 10. void crunch() throws IOException 11. Which method(s), inserted independently at line 7, compile? (Choose all that apply.)(分数:2.50)A.void crunch() B.void crunch() throws Exception C.void crunch(int x) throws Exception D.void crunch() throws RuntimeException E.void crunch()
21、throws FileNotFoundException 11.Given: 2. class Horse 3. String hands = “15“; 4. 5. class GaitedPony extends Horse 6. static String hands = “14“; 7. public static void main(String args) 8. String hands = “13.2“; 9. String result = new GaitedPony().getSize(hands); 10. System.out.println(“ “ + result)
22、; 11. 12. String getSize(String s) 13. System.out.print(“hands: “ + s); 14. return hands; 15. What is the result?(分数:2.50)A.14B.15C.hands: 13.2 14D.hands: 13.2 15E.Compilation fails.F.An exception is thrown at runtime.12.Given: 2. public class Humping 3. public static void main(String args) 4. Strin
23、g r = “-“; 5. char c = “a“, “b“, “c“, “z“; 6. for(char c1: c) 7. switch (c1) 8. case “a“: r += “a“; 9. case “b“: r += “b“; break; 10. default: r += “X“; 11. case “z“: r+= “z“; 12. 13. System. out.println(r); 14. What is the result?(分数:2.50)A.-abXzB.-abbXzC.-abbXzzD.-abbXzXzE.Compilation fails due to
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 JAVA 认证 答案 解析 DOC
