【计算机类职业资格】计算机Java认证-4及答案解析.doc
《【计算机类职业资格】计算机Java认证-4及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】计算机Java认证-4及答案解析.doc(35页珍藏版)》请在麦多课文档分享上搜索。
1、计算机 Java认证-4 及答案解析(总分:100.00,做题时间:90 分钟)一、不定项选择题(总题数:44,分数:100.00)1.Given: 2. public class Payroll 3. int salary; 4. int getSalary() return salary; 5. void setSalary(int s) 6. assert(s 30000); 7. salary = s; 8. Which are true? (Choose all that apply.)(分数:1.50)A.Compilation fails.B.The class is well
2、encapsulated as it stands.C.Removing line 6 would weaken the class“s degree of cohesion.D.Removing line 6 would weaken the class“s degree of encapsulation.E.If the salary variable was private, the class would be well encapsulated.F.Removing line 6 would make the class“s use of assertions more approp
3、riate.2.Given: 1. class GardenTool 2. static String s = “; 3. String name = “Tool “; 4. GardenTooi(String arg) this(); s += name; 5. GardenTool() s += “gt “; 6. 7. public class Rake extends GardenTool 8. name = “Rake “; 9. Rake(String arg) s += name; 10. public static void main(String args) 11. new
4、GardenTool(“hey “); 12. new Rake(“hi “); 13. System.out.println(s); 14. 15. name = “myRake “; 16. What is the result?(分数:1.50)A.Tool RakeB.Tool myRakeC.gt Tool RakeD.gt Tool myRakeE.gt Tool gt RakeF.gt Tool gt myRakeG.gt Tool gt Tool myRakeH.Compilation fails.3.Given: 3. public class Race 4. public
5、static void main(String args) 5. Horse h = new Horse(); 6. Thread t1 = new Thread(h, “Andi“); 7. Thread t2 = new Thread(h, “Eyra“); 8. new Race() .go(t2); 9. t1.start(); 10. t2.start(); 11. 12. void go(Thread t) t.start(); 13. 14. class Horse implements Runnable 15. public void run() 16. System.out.
6、print(Thread.currentThread() .getName() + “ “); 17. What is the result? (Choose all that apply.)(分数:1.50)A.Compilation fails.B.No output is produced.C.The output could be: “Andi Eyra“D.The output could be: “Eyra Andi Eyra“E.The output could be: “Eyra “, followed by an exception.F.The output could be
7、: “Eyra Andi “, followed by an exception.4.Given the proper import statement(s) and given: 4. MapString, String h = new HashtableString, String(); 5. String k = “1“, “2“, “3“, null; 6. String v = “a“, “b“, null, “d“; 7. 8. for(int i=0; i4; i+) 9. h.put(ki, vi); 10. System.out.print(h. get (k i) + “
8、“); 11. 12. System.out.print(h.size() + “ “ + h.values() + “/n“); What result is most likely?(分数:1.50)A.Compilation fails.B.“a b d 3 b, d, a“C.“a b null d 3 b, d, a“D.“a b null d 4 b, d, null, a“E.“a b“, followed by an exception.F.“a b null“, followed by an exception.5.Given: 3. public class Fiji 4.
9、 static Fiji base; 5. Fiji f; 6. public static void main(String args) 7. new Fiji() .go(); 8. / do more stuff 9. 10. void go() 11. Fiji f1 = new Fiji(); 12. base = f1; 13. Fiji f2 = new Fiji(); 14. f1.f = f2; 15. Fiji f3 = f1.f; 16. f2.f = f1; 17. base = null; f1 = null; f2 = null; 18. / do stuff 19
10、. Which are true? (Choose all that apply.)(分数:1.50)A.At line 8, one object is eligible for garbage collection.B.At line 8, two objects are eligible for garbage collection.C.At line 8, three objects are eligible for garbage collection.D.At line 18, 0 objects are eligible for garbage collection.E.At l
11、ine 18, two objects are eligible for garbage collection.F.At line 18, three objects are eligible for garbage collection.6.Your company makes compute-intensive, 3D rendering software for the movie industry. Your chief scientist has just discovered a new algorithm for several key methods in a commonly
12、 used utility class. The new algorithm will decrease processing time by 15 percent, without having to change any method signatures. After you change these key methods, and in the course of rigorous system testing, you discover that the changes have introduced no new bugs into the software. In terms
13、of your software“s overall design, which are probably true? (Choose all that apply.)(分数:1.50)A.Your software is well encapsulated.B.Your software demonstrated low cohesion.C.Your software demonstrated high cohesion.D.Your software demonstrated loose coupling.E.Your software demonstrated tight coupli
14、ng.7.Which are true about the classes and interfaces in j ava.util? (Choose all that apply.)(分数:1.50)A.LinkedHashSet is-a Collection.B.Vector is-a List.C.LinkedList is-a Queue.D.LinkedHashMap is-a Collection.E.TreeMap is-a SortedMap.F.Queue is-a Collection.G.Hashtable is-a Set.8.Given: 2. class Gran
15、dfather 3. static String name = “gf “; 4. String doStuff() return “grandf “; 5. 6. class Father extends Grandfather 7. static String name = “fa “; 8. String doStuff() return “father “; 9. 10. public class Child extends Father 11. static String name = “ch “; 12. String doStuff() return “child “; 13.
16、public static void main(String args) 14. Father f = new Father(); 15. System.out.print(Grandfather)f).name + (Grandfather)f) .doStuff(); 16. Child c = new Child(); 17. System. out.println(Grandfather) c) .name + (Grandfather)c) .doStuff() + (Father)c) .doStuff(); 18. What is the result? (Choose all
17、that apply.)(分数:1.50)A.Compilation fails.B.fa father ch child childC.gf father gf child childD.fa grandf ch grandf fatherE.gf grandf gf grandf fatherF.An exception is thrown at runtime.9.Given: 1. class MyClass And given that MyClass2 has properly overridden equals() and hashCode() objects from whic
18、h classes make good hashing keys? (Choose all that apply.)(分数:1.50)A.MyClassB.MyClass2C.java.lang.StringD.java.lang.IntegerE.java.lang.StringBuilder10.Given: 2. public class Buffalo 3. static int x; 4. int y; 5. public static int getX() return x; 6. public static void setX(int newX) x = newX; 7. pub
19、lic int getY() return y; 8. public void setY(int newY) y = newY; 9. Which lines of code need to be changed to make the class thread safe? (Choose all that apply.)(分数:1.50)A.Line 2B.Line 3C.Line 4D.Line 5E.Line 6F.Line 7G.Line 811.Given: 2. class Animal 3. class Dog extends Animal 4. class Cat extend
20、s Animal 5. public class MixerA extends Animal 6. public C extends Cat Mixer? super Dog useMe(A a, C c) 7. /Insert Code Here 8. Which, inserted independently at line 7, compile? (Choose all that apply.)(分数:2.50)A.return null;B.return new MixerDog();C.return new MixerAnimal();D.return new MixerA();E.
21、return new Mixera();F.return new Mixerc();12.Given: 2. class Chilis 3. Chilis(String c, int h) color = c; hotness = h; 4. String color; 5. private int hotness; 6. public boolean equals(Object o) 7. Chilis c = (Chilis)o; 8. if(color.equals(c.color) 9. return false; 10. 11. / insert code here 12. Whic
22、h, inserted independently at line 11, fulfill the equals() and hashCode() contract for Chilis? (Choose all that apply.)(分数:2.50)A.public int hashCode() return 7; B.public int hashCode() return hotness; C.public int hashCode() return color.length(); D.public int hashCode() return (int)(Math.random()
23、* 200); E.public int hashCode() return (color.length() + hotness); 13.Given the proper import(s), and this code in a method: 4. ListString x = new LinkedListString(); 5. SetString hs = new HashSetString(); 6. String v = “a“, “b“, “c“, “b“, “a“; 7. for(String s: v) 8. x.add(s); hs.add(s); 9. 10. Syst
24、em.out.print(hs.size() + “ “ + x.size() + “ “); 11. HashSet hs2 = new HashSet(x); 12. LinkedList x2 = new LinkedList(hs); 13. System.out.println(hs2.size() + “ “ + x2.size(); What is the result?(分数:2.50)A.3 3 3 3B.3 5 3 3C.3 5 3 5D.5 5 3 3E.5 5 5 5F.Compilation fails.G.An exception is thrown at runt
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 JAVA 认证 答案 解析 DOC
