【计算机类职业资格】计算机Java认证-5及答案解析.doc
《【计算机类职业资格】计算机Java认证-5及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】计算机Java认证-5及答案解析.doc(41页珍藏版)》请在麦多课文档分享上搜索。
1、计算机 Java认证-5 及答案解析(总分:100.00,做题时间:90 分钟)一、不定项选择题(总题数:44,分数:100.00)1.Given: 3. class Department 4. Department getDeptName() return new Department(); 5. 6. class Accounting extends Department 7. Accounting getDeptName() return new Accounting(); 8. / insert code here 13. And the following four code fra
2、gments: . String getDeptName(int x) return “mktg“; . void getDeptName(Department d) ; . void getDeptName(long x) throws NullPointerException throw new NullPointerException(); . Department getDeptName() throws NullPointerException throw new NullPointerException(); return new Department(); Which are t
3、rue? (Choose all that apply.)(分数:1.50)A.If fragment is inserted at line 8, the code compiles.B.If fragment is inserted at line 8, the code compiles.C.If fragment is inserted at line 8, the code compiles.D.If fragment is inserted at line 8, the code compiles.E.If none of the fragments are inserted at
4、 line 8, the code compiles.2.Given: 2. import java.util.*; 3. interface Canine 4. class Dog implements Canine 5. public class Collie extends Dog 6. public static void main(String args) 7. ListDog d = new ArrayListDog(); 8. ListCollie c = new ArrayListCollie(); 9. d. add (new Collie(); 10. c. add (ne
5、w Collie(); 11. do1(d); do1(c); 12. do2(d); do2(c); 13. 14. static void dol (List? extends Dog d2) 15. d2.add(new Collie(); 16. System.out.print(d2.size(); 17. 18. static void do2(List? extends Canine c2) 19. Which are true? (Choose all that apply.)(分数:1.50)A.Compilation succeeds.B.Compilation fails
6、 due to an error on line 9.C.Compilation fails due to an error on line 14.D.Compilation fails due to an error on line 15.E.Compilation fails due to an error on line 16.F.Compilation fails due to an error on line 18.G.Compilation fails due to errors on lines 11 and 12.3.Given: 42. void go() 43. int c
7、ows = 0; 44. int twisters = 1,2,3; 45. for(int i = 0; i 4; i+) 46. switch(twistersi) 47. case 2: cows+; 48. case 1: cows += 10; 49. case 0: go(); 50. 51. System.out.println(cows); 52. What is the result?(分数:1.50)A.11B.21C.22D.Compilation fails.E.A StackOverflowError is thrown at runtime.F.An Arrayln
8、dexOutOfBoundsException is thrown at runtime.4.Given: 2. class Robot 3. interface Animal 4. class Feline implements Animal 5. public class BarnCat extends Feline 6. public static void main(String args) 7. Animal af = new Feline(); 8. Feline ff = new Feline(); 9. BarnCat b = new BarnCat(); 10. Robot
9、r = new Robot(); 11. if(af instanceof Animal) System.out.print(“1 “); 12. if(af instanceof BarnCat) System.out.print(“2 “); 13. if(b instanceof Animal) System.out.print(“3 “); 14. if(ff instanceof BarnCat) System.out.print (“4 “); 15. if(r instanceof Animal) System.out .print (“5 “); 16. 17. What is
10、 the result?(分数:1.50)A.1B.1 3C.1 2 3D.1 3 4E.1 2 3 4F.Compilation fails.G.An exception is thrown at runtime.5.Given: 2. public class Sunny extends Weather 3. public static void main(String args) 4. try 5. new Sunny() .do1(); 6. new Sunny() .do2(); 7. new Sunny() .do3(); 8. 9. catch(Throwable t) Syst
11、em.out.print(“exc “); 10. 11. class Weather 12. void do1() System.out.print(“do1 “); 13. private void do2() System.out.print(“do2 “); 14. protected void do3() System.out.print(“do3 “); 15. What is the result?(分数:1.50)A.do1 excB.do1 do2 excC.do1 do2 do3D.Compilation fails.E.An exception is thrown at
12、runtime.6.Given that FileNotFoundException extends IOException and given: 2. import java.io.*; 3. public class Changeup 4. public static void main(String args) throws IOException 5. new Changeup() .go(); 6. new Changeup() .go2(); 7. new Changeup() .go3(); 8. 9. void go() throw new IllegalArgumentExc
13、eption(); 10. 11. void go2() throws FileNotFoundException 12. 13. void go3() 14. try throw new Exception(); 15. catch (Throwable th) throw new NullPointerException(); 16. What is the result? (Choose all that apply.)(分数:1.50)A.An IOException is thrown at runtime.B.A NullPointerException is thrown at
14、runtime.C.An IllegalArgumentException is thrown at runtime.D.Compilation fails due to an error at line 4.E.Compilation fails due to an error at line 9.F.Compilation fails due to an error at line 11.G.Compilation fails due to an error at line 15.7.Which are true? (Choose all that apply.)(分数:1.50)A.If
15、 class A is-a class B, then class A cannot be considered well encapsulated.B.If class A has-a class B, then class A cannot be considered well encapsulated.C.If class A is-a class B, then the two classes are said to be cohesive.D.If class A has-a class B, then the two classes are said to be cohesive.
16、E.If class A is-a class B, it“s possible for them to still be loosely coupled.F.If class A has-a class B, it“s possible for them to still be loosely coupled.8.Given: 2. import java.util.*; 3. public class Volleyball 4. public static void main(String args) 5. TreeSetString s = new TreeSetString(); 6.
17、 s.add(“a“); s.add(“f“); s.add(“b“); 7. System.out.print(s + “ “); 8. Collections.reverse(s); 9. System.out.println(s); 10. What is the result?(分数:1.50)A.Compilation fails.B.a, b, f a, b, fC.a, b, f f, b, aD.a, f, b b, f, aE.a, b, f, followed by an exception.F.a, f, b, followed by an exception.9.Giv
18、en: 2. public class Boggy 3. final static int mine = 7; 4. final static Integer i = 57; 5. public static void main(String args) 6. int x : go(mine); 7. System.out.print(mine + “ “ + x + “ “); 8. x += mine; 9. Integer i2 = i; 10. i2 = go(i); 11. System.out.println(x + “ “ + i2); 12. i2 = new Integer(
19、60); 13. 14. static int go(int x) return +x; 15. What is the result?(分数:1.50)A.7 7 14 57B.7 8 14 57C.7 8 15 57D.7 8 15 58E.7 8 16 58F.Compilation fails.G.An exception is thrown at runtime.10.Given: 3. import java.io.*; 4. public class Kesey 5. public static void main(String args) throws Exception 6.
20、 File file = new File(“bigData.txt“); 7. FileWriter w = new FileWriter(file); 8. w.println(“lots o“ data“); 9. w.flush(); 10. w.close(); 11. What is the result? (Choose all that apply.)(分数:1.50)A.An empty file named “bigData.txt“ is created.B.Compilation fails due only to an error on line 5.C.Compil
21、ation fails due only to an error on line 6.D.Compilation fails due only to an error on line 7.E.Compilation fails due only to an error on line 8.F.Compilation fails due to errors on multiple lines.G.A file named “bigData.txt“ is created, containing one line of data.11.Given: 3. class Wanderer implem
22、ents Runnable 4. public void run() 5. for(int i = 0; i 2; i+) 6. System.out.print(Thread.currentThread() .getName() + “ “); 7. 8. public class Wander 9. public static void main(String args) 10. Wanderer w = new Wanderer(); 11. Thread t1 = new Thread(); 12. Thread t2 = new Thread(w); 13. Thread t3 =
23、new Thread(w, “fred“); 14. t1.start(); t2.start(); t3.start(); 15. Which are true? (Choose all that apply.)(分数:2.50)A.Compilation fails.B.No output is produced.C.The output could be Thread- 1 fred fred Thread- 1D.The output could be Thread-1 Thread-1 Thread-2 Thread-2E.The output could be Thread-1 f
24、red Thread-1 Thread-2 Thread-2 fredF.The output could be Thread-1 Thread-1 Thread-2 Thread-3 fred fred12.Given: 2. import java.util.*; 3. public class MyFriends 4. String name; 5. MyFriends(String s) name = s; 6. public static void main(String args) 7. SetMyFriends ms = new HashSetMyFriends(); 8. ms
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 JAVA 认证 答案 解析 DOC
