【计算机类职业资格】计算机Java认证-1及答案解析.doc

上传人:周芸 文档编号:1336848 上传时间:2019-10-17 格式:DOC 页数:39 大小:149.50KB
下载 相关 举报
【计算机类职业资格】计算机Java认证-1及答案解析.doc_第1页
第1页 / 共39页
【计算机类职业资格】计算机Java认证-1及答案解析.doc_第2页
第2页 / 共39页
【计算机类职业资格】计算机Java认证-1及答案解析.doc_第3页
第3页 / 共39页
【计算机类职业资格】计算机Java认证-1及答案解析.doc_第4页
第4页 / 共39页
【计算机类职业资格】计算机Java认证-1及答案解析.doc_第5页
第5页 / 共39页
点击查看更多>>
资源描述

1、计算机 Java 认证-1 及答案解析(总分:100.00,做题时间:90 分钟)一、不定项选择题(总题数:44,分数:100.00)1.Given: 2. public class Bunnies 3. static int count=0; 4. Bunnies() 5. while (count10) new Bunnies (+count); 6. 7. Bunnies (int x) super(); 8. public static void main (String args) 9. new Bunnies(); 10. new Bunnies (count); 11. Syst

2、em. out. println (count+); 12. 13. What is the result?(分数:1.50)A.9B.10C.11D.12E.Compilation fails.F.An exception is thrown at runtime.2.Given: 2. public class Jail 3. private int x=4; 4. public static void main (String args) 5. protected int x=6; 6. new Jail() .new Cell() .slam(); 7. 8. class Cell 9

3、. void slam() System.out.println (“throw away key“ + x); 10. 11. Which are true? (Choose all that apply.)(分数:1.50)A.Compilation succeeds.B.The output is “throw away key 4“.C.The output is “throw away key 6“.D.Compilation fails due to an error on line 5.E.Compilation fails due to an error on line 6.F

4、.Compilation fails due to an error on line 9.3.Given: 2. public class Fabric extends Thread 3. public static void main (String args) 4. Thread t=new Thread (new Fabric(); 5. Thread t2=new Thread (new Fabric(); 6. t.start(); 7. t2.start(); 8. 9. public static void run() 10. for(int i=0; i2; i+) 11. S

5、ystem.out.print (Thread.currentThread() .getName() +“ “); 12. 13. Which are true? (Choose all that apply.)(分数:1.50)A.Compilation fails.B.No output is produced.C.The output could be Thread-1 Thread-3 Thread-1 Thread-2D.The output could be Thread-1 Thread-3 Thread-1 Thread-3E.The output could be Threa

6、d-1 Thread-1 Thread-2 Thread-2F.The output could be Thread-1 Thread-3 Thread-3 Thread-1G.The output could be Thread-1 Thread-3 Thread-1 Thread-14.Given: 2. class Feline 3. public class BarnCat2 extends Feline 4. public static void main (String args) 5. Feline ff=new Feline(); 6. BarnCat2 b=new BarnC

7、at2 (); 7. / insert code here 8. 9. Which, inserted independently at line 7, compile? (Choose all that apply.)(分数:1.50)A.if(b instanceof ff) System.out.print(“1 “);B.if(b.instanceof(ff) System.out.print(“2 “);C.if(b instanceofFeline) System.out.print(“3 “);D.if(b instanceOf Feline) System.out.print(

8、“4 “);E.if(b.instanceof(Feline) System.out.print(“5 “);5.Given: 2. public class Choosy 3. public static void main (String args) 4. String result=“ “; 5. int x=7, y=8; 6. if(x=3) result += “i“; 7. else if (x9) result += “2“; 8. else if (y9) result += “3“; 9. else if (x=7) result += “4“; 10. else resu

9、lt += “5“; 11. System.out.println (result); 12. 13. What is the result? (Choose all that apply.)(分数:1.50)A.3B.34C.35D.345E.Compilation fails due to an error on line 5.F.Compilation fails due to errors on lines 8 and 9.G.Compilation fails due to errors on lines 7, 8, and 96.Given: 1. public class Twi

10、ne 2. public static void main (String args) 3. String s=“; 4. StringBuffer sb1=new StringBuffer(“hi“); 5. StringBuffer sb2=new StringBuffer(“hi“); 6. StringBuffer sb3=new StringBuffer(sb2); 7. StringBuffer sb4=sb3; 8. if(sb1.equals(sb2) s += “1 “; 9. if(sb2.equals(sb3) s += “2 “; 10. if(sb3.equals(s

11、b4) s += “3 “; 11. String s2=“hi“; 12. String s3=“hi“; 13. String s4=s3; 14. if(s2.equals(s3) s += “4 “; 15. if(s3.equals(s4) s += “5 “; 16. System.out.println(s); 17. 18. What is the result?(分数:1.50)A.13B.15C.123D.145E.345F.1345G.12345H.Compilation fails.7.Which are true? (Choose all that apply.)(分

12、数:1.50)A.All classes of Exception extend Error.B.All classes of Error extend Exception.C.All Errors must be handled or declared.D.All classes of Exception extend Throwable.E.All Throwables must be handled or declared.F.All Exceptions must be handled or declared.G.RuntimeExceptions need never be hand

13、led or declared.8.Given: 2. import java.util.*; 3. public class Birthdays 4. public static void main(String args) 5. MapFriends, String hm=new HashMapFriends, String(); 6. hm.put(new Friends(“Charis“), “Summer 2009“); 7. hm.put(new Friends(“Draumur“), “Spring 2002“); 8. Friends f=new Friends(args0);

14、 9. System. out.println (hm.get(f); 10. 11. 12. class Friends 13. String name; 14. Friends(String n) name=n; 15. And the command line invocation: java Birthdays Draumur What is the result? A. null B. Draumur C. Spring 2002 D. Compilation fails. E. The output is unpredictable. F. An exception is thro

15、wn at runtime. G FriendsXXXX (where XXXX is a representation of a hashcode) (分数:1.50)A.B.C.D.E.F.G.9.Given: 2. import java.util.*; 3. class Cereal 4. public class Flakes extends Cereal 5. public static void main(String args) 6. ListFlakes c0=new ListFlakes(); 7. ListCereal c1=new ArrayListCereal();

16、8. ListCereal c2=new ArrayListFlakes(); 9. ListFlakes c3=new ArrayListCereal(); 10. ListObject c4=new ArrayListFlakes(); 11. ArrayListCereal c5=new ArrayListFlakes(); 12. 13. Which are true? (Choose all that apply.)(分数:1.50)A.Compilation succeeds.B.Compilation fails due to an error on line 6.C.Compi

17、lation fails due to an error on line 7.D.Compilation fails due to an error on line 8.E.Compilation fails due to an error on line 9.F.Compilation fails due to an error on line 10.G.Compilation fails due to an error on line 11.10.Given: 3. public class RediMix extends Concrete 4. RediMix() System.out.

18、println(“r “); 5. public static void main(String args) 6. new RediMix(); 7. 8. 9. class Concrete extends Sand 10. Concrete() System.out.print(“c “); 11. private Concrete(String s) 12. 13. abstract class Sand 14. Sand() System.out.print(“s “); 15. What is the result?(分数:1.50)ArB.c rC.r cD.s c rE.r c

19、sF.Compilation fails due to a single error in the code.G.Compilation fails due to multiple errors in the code.11.Which statement(s) are true? (Choose all that apply.)(分数:2.50)A.Coupling is the OO principle most closely associated with hiding a class“s implementation details.B.Coupling is the OO prin

20、ciple most closely associated with making sure classes know about other classes only through their APIs.C.Coupling is the OO principle most closely associated with making sure a class is designed with a single, well-focused purpose.D.Coupling is the OO principle most closely associated with allowing

21、 a single object to be seen as having many types.12.Given: 2. class Mosey implements Runnable 3. public void run() 4. for(int i=0; i1000; i+) 5. System.out.print(Thread.currentThread() .getId() +“-“+i+“ “); 6. 7. public class Stroll 8. public static void main(String args) throws Exception 9. Thread

22、t1=new Thread(new Mosey(); 10. /insert code here 11. 12. Which of the following code fragments, inserted independently at line 10, will probably run most (or all) of the main thread“s run() method invocation before running most of the t1 thread“s run() method invocation? (Choose all that apply.)(分数:

23、2.50)A.t1.setPriority(1);new Mosey().run();t1.start();B.t1.setPriority(9);new Mosey().run();t1.start();C.t1.setPriority(1);t1.start();new Mosey().run();D.t1.setPriority(8);t1.start();new Mosey().run();13.Given: 37. boolean b=false; 38. int i=7; 39. double d=1.23; 40. float f=4.56f; 41. 42. / insert

24、code here Which line(s) of code, inserted independently at line 42, will compile and run without exception? (Choose all that apply.)(分数:2.50)A.System.out.printf(“ %b“, b);B.System.out.printf(“ %i“, i);C.System.out.format(“ %d“, d);D.System.out.format(“ %d“, i);E.System.out.format(“ %f“, f);14.Given:

25、 1. import java.util.*; 2. public class MyPancake implements Pancake 3. public static void main(String args) 4. ListString x=new ArrayListString(); 5. x.add(“3“); x.add (“7“); x.add (“5“); 6. ListString y=new MyPancake() .doStuff(x); 7. y.add (“i“); 8. System.out.println (x); 9. 10. ListString doStu

26、ff(ListString z) 11. z.add(“9“); 12. return z; 13. 14. 15. interface Pancake 16. ListString doStuff(ListString s); 17. What is the most likely result?(分数:2.50)A.3,7,5B.3,7,5,9C.3,7,5,9,1D.Compilation fails.E.An exception is thrown at runtime.15.Given: 3. import java.util.*; 4. public class VLA2 impl

27、ements ComparatorVLA2 5. int dishSize; 6. public static void main(String args) 7. VLA2 va=new VLA2(40), new VLA2(200), new VLA2(60) ; 8. 9. Arrays.sort(va, va0); 10. int index=Arrays.binarySearch(va, new VLA2(40), va0); 11. System.out.print(index +“ “); 12. index=Arrays.binarySearch(va, new VLA2(80)

28、, va0); 13. System.out.print(index); 14. 15. public int compare(VLA2 a, VLA2 b) 16. return b.dishSize - a.dishSize; 17. 18. VLA2(int d) dishSize=d; 19. What is the result?(分数:2.50)A.0-2B.0-3C.2-1D.2-2E.Compilation fails.F.An exception is thrown at runtime.16.Given a directory structure: - baseDir -

29、testDir - subDir2 - Shackelton.txt and given the following code: 12. String name = “testDir“ + File.pathSeparator + “subDir2“ + File.pathSeparator + “Shackelton.txt“; 13. File f = new File (name); 14. System.out.println(“exists “ + f.exists(); Assuming the proper import statements and exception hand

30、ling, which statements must be true in order for the output to be “exists true“? (Choose three.)(分数:2.50)A.Line 12 is correct as it stands.B.Line 14 is correct as it stands.C.The program must be invoked from the baseDir directory.D.The program must be invoked from the testDir directory.E.Line 12 mus

31、t use File.separator instead of File.pathSeparator.F.Line 14 must use the method fileExists() instead of exists().17.Given: 1. import java.io.*; 2. import java.util.*; 3. import static java.lang. Short.*; 4. import static java.lang. Long.*; 5. public class MathBoy 6. public static void main(String a

32、rgs) 7. long x = 123456789; 8. short y = 22766; / maximum value of a short is 32767 9. System.out.printf(“%1$+10d %2$010d “, x, MAX VALUE - y); 10. System.out.println(new Date(); 11. 12. Which are true? (Choose all that apply.)(分数:2.50)A.Compilation fails.B.The output will include “+“C.The output wi

33、ll include “10001“D.The output will include “0000010001“E.The output will include today“s date.F.The output will include the number of milliseconds from January 1, 1970 until today.18.Given: 1. public class WeatherTest 2. static Weather w; 3. public static void main(String args) 4. System.out.print(

34、w.RAINY.count + “ “ + w. Sunny . count + “ “); 5. 6. 7. enum Weather 8. RAINY, Sunny; 9. int count = 0; 10. Weather() 11. System.out.print(“c “); 12. count+; 13. 14. What is the result?(分数:2.50)A.c1c1B.c1c2C.cc11D.cc12E.cc22F.Compilation fails.G.An exception is thrown at runtime.19.Given: 2. import

35、java.text.*; 3. public class Gazillion 4. public static void main(String args) throws Exception 5. String s = “123.456xyz“; 6. NumberFormat nf = NumberFormat.getInstance(); 7. System.out.println (nf.parse(s); 8. nf.setMaximumFractionDigits(2); 9. System.out.println (nf.format(s); 10. 11. Which are t

36、rue? (Choose all that apply.)(分数:2.50)A.Compilation fails.B.The output will contain “123.45 “C.The output will contain “123.456“D.The output will contain “123.456xyz“E.An exception will be thrown at runtime.20.Given that the current directory is bigApp, and the following directory structure: bigApp

37、|- classes |- com |- wickedlysmart |- BigAppMain.class And the code: package com.wickedlysmart; public class BigAppMain public static void main(String args) System. out.println(“big app“); Which will invoke BigAppMain? (Choose all that apply.)(分数:2.50)A.java classes/com.wickedlysmart.BigAppMainB.jav

38、a classes com/wickedlysmart/BigAppMainC.java .wickedlysmart.BigAppMainD.java -cp classes com.wickedlysmart.BigAppMainE.java -cp /classes com.wickedlysmart.BigAppMainF.java -cp .:classes com.wickedlysmart.BigAppMainG.java -cp classes/com/wickedlysmart com.wickedlysmart.BigAppMain21.Given: 2. class Ga

39、me 3. static String s = “-“; 4. String s2 = “s2“; 5. Game (String arg) s += arg; 6. 7. public class Go extends Game 8. Go() super(s2); 9. s += “i “; 10. public static void main(String args) 11. new Go (); 12. System.out.println(s); 13. 14. static s += “sb “; 15. What is the result?(分数:2.50)A.-sb i s

40、2B.-sb s2 iC.-s2 i sbD.-s2 sb iE.Compilation fails.F.An exception is thrown at runtime.22.Given: 2. public class Salmon extends Thread 3. public static long id; 4. public void run() 5. for(int i = 0; i4; i+) 6. / insert code here 7. new Thread(new Salmon() .start(); 8. throw new Error(); 9. 10. Syst

41、em.out.print (i +“ “); 11. 12. public static void main(String args) 13. Thread t1 = new Salmon(); 14. id = t1.getId(); 15. t1.start (); 16. And the two code fragments: . if(i = 2 4. public static void main(String args) 5. new Internet() .go(); 6. 7. void go() 8. int x = 7; 9. TCPIP ip = new TCPIP();

42、 10. class TCPIP 11. void doit() System.out.println(y + x); 12. 13. ip.doit (); 14. 15. What is the result? (Choose all that apply.)(分数:2.50)A.Compilation succeeds.B.Compilation fails due to an error on line 3.C.Compilation fails due to an error on line 8.D.Compilation fails due to an error on line

43、9.E.Compilation fails due to an error on line 10.F.Compilation fails due to accessing x on line 11.G.Compilation fails due to accessing y on line 11.24.Given: 4. public static void main(String args) 5. try 6. if(args.length = 0) throw new Exception(); 7. 8. catch (Exception e) 9. System.out .print (

44、“done “); 10. doStuff(); / assume this method compiles 11. 12. finally 13. System.out.println(“finally “); 14. 15. Which are possible outputs? (Choose all that apply.)(分数:2.50)A.“done “B.“finally“C.“done finally“D.Compilation fails.E.No output is produced.25.Given: 3. class A 4. class B extends A 5.

45、 class C extends B 6. public class CarpetV extends B 7. public X extends V Carpet? extends V method(Carpet? super X e) 8. / insert code here 9. Which, inserted independently at line 8, will compile? (Choose all that apply.)(分数:2.50)A.return new CarpetX();B.return new CarpetV();C.return new CarpetA()

46、;D.return new CarpetB();E.return new CarpetC();26.Given: 1. class One 2. int x = 0; 3. assert x = i; 4. 5. public class Two 6. public static void main(String args) 7. int y = 0; 8. assert y = 0; 9. if(args.length 0) 10. new One(); 11. 12. Which of the following will mn without error? (Choose all tha

47、t apply.)(分数:2.50)A.java TwoB.java Two xC.java -ea TwoD.java -ea Two xE.java -ea:One TwoF.java -ea:One Two xG.java -ea:Two Two x27.Given: 2. class SafeDeposit 3. private static SafeDeposit singleton; 4. public static SafeDeposit getInstance(int code) 5. if(singleton = null) 6. singleton = new SafeDe

48、posit(code); 7. return singleton; 8. 9. private int code; 10. private SafeDeposit(int c) code = c; 11. int getCode() return code; 12. 13. public class BeSafe 14. / insert lots of code here 25. Which are true? (Choose all that apply.)(分数:2.50)A.Compilation fails.B.Class BeSafe can create many instances of SafeDeposit.C.Class BeSafe CANNOT create any instances o

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试资料 > 职业资格

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1