【计算机类职业资格】计算机Java认证-6及答案解析.doc
《【计算机类职业资格】计算机Java认证-6及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】计算机Java认证-6及答案解析.doc(43页珍藏版)》请在麦多课文档分享上搜索。
1、计算机 Java认证-6 及答案解析(总分:100.00,做题时间:90 分钟)一、不定项选择题(总题数:42,分数:100.00)1.Given: 4. class Electricity int getCharge() return 24; 5. public class Voltage extends Electricity 6. enum volts twelve, twentyfour, oneten; 7. public static void main(String args) 8. volts v = velts.twentyfour; 9. switch (v) 10. ca
2、se twelve: 11. System.out.print(“12 “); 12. default: 13. System.out.print (getCharge() + “ “); 14. case oneten: 15. System.out.print(“110 “); 16. What is the result? (Choose all that apply.)(分数:1.50)A.24B.24 110C.24 110 12D.Compilation fails due to a misuse of enums.E.Compilation fails due to a non-
3、enum issue.2.Given: 2. import java.io.*; 3. public class Uboat 4. public static void main(String args) 5. try 6. File f1 = new File(“sub1“); 7. f1.mkdir(); 8. File f2 = new File(f1, “sub2“); 9. File f3 = new File(f1, “sub3“); 10. PrintWriter pw = new PrintWriter(f3); 11. catch (Exception e) System.o
4、ut.println(“ouch“); 12. And, if the code compiles, what is the result if “java Uboat“ is invoked TWICE? (Choose all that apply.)(分数:1.50)A.Compilation fails.B.The second invocation produces the output “ouch“.C.The second invocation creates at least one new file as a peer to the new directory.D.The f
5、irst invocation creates a new directory and one new file in that directory.E.The first invocation creates a new directory and two new files in that directory.F.The first invocation creates a new directory and at least one new file as a peer to it.3.Given: 2. class Car 3. private Car() 4. protected C
6、ar(int x) 5. 6. public class MG extends Car 7. / MG(int x) 8. / MG(int x) super(); 9. / MG(int x) super(x); 10. / private MG(int x) super(x); 11. / MG() 12. / MG() this(); 13. / MG() this(6); 14. / MG() super(7); 15. public static void main(String args) 16. new MG(7); 17. new MG(); 18. Which sets of
7、 constructors can be uncommented for the code to compile? (Choose all that apply.)(分数:1.50)A.Line 7 and line 11.B.Line 7 and line 14.C.Line 8 and line 12.D.Line 8 and line 13.E.Line 9 and line 12.F.Line 9 and line 13.G.Line 10 and line 11.H.Line 10 and line 14.4.Given: 2. interface Gadget 3. int pat
8、ent = 12345; 4. Gadget doStuff(); 5. 6. public class TimeMachine implements Gadget 7. int patent = 34567; 8. public static void main(String args) 9. new TimeMachine().doStuff(); 10. 11. TimeMachine doStuff() 12. System.out.println( +patent); 13. return new TimeMachine(); 14. If javac is invoked twic
9、e: javac -source 1.4 TimeMachine.Java javac TimeMachine. java And, if“java TimeMachine“ is invoked whenever TimeMachine compiles, what is the result?(分数:1.50)A.First, compilation fails, then 12346B.First, compilation fails, then 34568C.First, 12346, then compilation fails.D.First, 34568, then compil
10、ation fails.E.First, 12346, then 34568F.Compilation fails on both javac invocations.5.Given: 1. import java.util.*; 2. public class LogSplitter 3. public static void main(String args) 4. for(int x = i; x args.length; x+) 5. System.out.print(args0 .split(argsx) .length + “ “); 6. And the command-line
11、 invocation: java LogSplitter “x1 23 y #“ “/d“ “/s“ “/w“ What is the result?(分数:1.50)A.4 4 6B.3 3 6C.5 4 6D.4 6 4E.3 6 3F.5 6 4G.Compilation fails.H.An exception is thrown at runtime.6.Given this code in a method: 3. int y, count = 0; 4. for(int x = 3; x 6; x+) 5. try 6. switch(x) 7. case 3: count+;
12、 8. case 4: count+; 9. case 7: count+; 10. case 9: y = 7 / (x - 4); count += 10; 11. 12. catch (Exception ex) count+; 13. 14. System.out.println(count); What is the result? A. 2 B. 15 C. 16 D. 25 E. 26 F Compilation fails. G. An exception is thrown with no other output. (分数:2.50)A.B.C.D.E.F.G.7.Give
13、n: 5. abstract class Thing static String s = “; Thing() s += “t “; 6. class Steel extends Thing 7. Steel() s += “s “; 8. Steel (String s1) 9. s += s1; 10. new Steel(); 11. 12. 13. public class Tungsten extends Steel 14. Tungsten(String s1) 15. s += s1; 16. new Steel(s); 17. 18. public static void ma
14、in(String args) 19. new Tungsten(“tu “); 20. System.out.println(s); 21. What is the result?(分数:2.50)A.s tu s tu sB.t s tu t s t sC.t s tu t t s tu t sD.t tu t s tu t t tu t s tu t sE.Compilation fails.F.An exception is thrown at runtime.8.Given: 2. public class Swanky 3. Swanky s; 4. public static v
15、oid main(String args) 5. Swanky s1 = new Swanky(); 6. s1.s = new Swanky(); 7. go (s1. s); 8. Swanky s2 = go(s1); 9. if(s2.s.equals(s1) System.out.print(“1 “); 10. if(s2.equals(s1) System.out.print (“2 “); 11. if(s1.s.equals(s1) System.out.print(“3 “); 12. if(s2.s.equals(s2) System.out.print(“4 “); 1
16、3. 14. static Swanky go(Swanky s) 15. Swanky gs = new Swanky(); 16. gs.s = s; 17. return gs; 18. What is the result?(分数:2.50)A.1B.1 2C.1 2 4D.Compilation fails.E.“1 “, followed by an exception.F.“1 2 “, followed by an exception.9.Given: 2. import java.util.*; 3. public class AndOver 4. public static
17、 void main(String args) 5. List g = new ArrayList(); 6. g.add(new Gaited(“Eyra“); 7. g.add(new Gaited(“Vafi“); 8. g.add(new Gaited(“Andi“); 9. Iterator i2 = g.iterator(); 10. while(i2.hasNext() 11. System.out.print(i2.next().name + “ “); 12. 13. class Gaited 14. public String name; 15. Gaited(String
18、 n) name = n; 16. What is the result?(分数:2.50)A.Vail AndiB.Andi Eyra VailC.Andi Vail EyraD.Eyra Vail AndiE.Compilation fails.F.The output order is unpredictable.10.Given: 2. interface Plant 3. int greenness = 7; 4. void grow(); 5. 6. class Grass implements Plant 7. / static int greenness = 5; 8. / i
19、nt greenness = 5; 9. public static void main(String args) 10. int greenness = 2; 11. new Grass().grow(); 12. 13. public void grow() 14. System.out.println(+greenness); 15. Which are true? (Choose all that apply.)(分数:2.50)A.As the code stands, the output is 3.B.As the code stands, the output is 8.C.A
20、s the code stands, it will NOT compile.D.If line 7 is un-commented, the output is 6.E.If line 8 is un-commented, the output is 6.F.If line 7 is un-commented, the output is 8.G.If line 7 is un-commented, the code will NOT compile.11.Given: 2. class Grab 3. static int x = 5; 4. synchronized void adjus
21、t(Grab y) 5. System.out.print(x- + “ “); 6. y.view(y); 7. 8. synchronized void view(Grab z) if(x 0) z.adjust(z); 9. 10. public class Grapple implements Runnable 11. static Thread t1; 12. static Grab g, g2; 13. public void run() 14. if(Thread.currentThread().getId() = t1.getId() g.adjust(g2); 15. els
22、e g2.view(g); 16. 17. public static void main(String args) 18. g = new Grab(); 19. g2 = new Grab(); 20. t1 = new Thread(new Grapple(); 21. t1.start(); 22. new Thread(new Grapple().start(); 23. Which are true? (Choose all that apply.)(分数:2.50)A.Compilation fails.B.The output could be 5 4 3 2 1C.The o
23、utput could be 5 4 3 2 1 0D.The program could produce thousands of lines of output.E.The program could deadlock before producing any output.F.The output could be “5 “, followed by the program deadlocking.12.Given: 3. import java.util.*; 4. public class Corner 5. public static void main(String args)
24、6. TreeSetString t1 = new TreeSetString(); 7. TreeSetString t2 = new TreeSetString(); 8. t1.add(“b“); t1.add(“7“); 9. t2 = (TreeSet)t1.subSet(“5“, “c“); 10. try 11. t1.add(“d“); 12. t2.add(“6“); 13. t2.add(“3“); 14. 15. catch (Exception e) System.out.print(“ex “); 16. System.out.println(t1 + “ “ + t
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 JAVA 认证 答案 解析 DOC
