【正文】
.*。 E. import ()。 G. static import 。格式 import static ...... import static 。 import static .*。 UNIX user named Bob wants to replace his chess program with a new one, but he is not sure where the old one is installed. Bob is currently able to run a Java chess program starting from his home directory /home/bob using the mand: java classpath /test:/home/bob/downloads/*.jar Bob39。所以 C 可能正確。 : 3. interface Animal { void makeNoise()。 6. public void makeNoise() { (whinny)。 } 10. public static void main(String[] args) { 11. Icelandic i1 = new Icelandic()。 13. Icelandic i3 = new Icelandic()。 i1 = i2。 i3 = i1。 我們假設(shè) 13 行結(jié)束的時(shí)候, i1 引用的對象叫 A, i2 引用的對象叫 B, i3 引用的對象叫 C。注意, A, B 對象中含有 Long 類型的對象,所以,一共有 4 個(gè)變量可以被回收。 2. public class BitUtils { 3. private static void process(byte[] b) {} 4. } 1. package app。 5. // insert code here 6. } 7. } What is required at line 5 in class SomeApp to use the process method of BitUtils? A. process(bytes) 。 C. (bytes) 。 E. import .*。 F. SomeApp cannot use the process method in BitUtils. Answer: F private,根本就不能使用。 13. public ItemTest(int id) { = id。 } 15. 16. public static void main(String[] args) { 17. ItemTest fa = new ItemTest(42)。 19. ()。 : 13. public class Pass { 14. public static void main(String [] args) { 15. int x = 5。 17. (x)。 19. } 20. 21. void doStuff(int x) { 22. ( doStuff x = + x++)。 : 1. public class GC { 2. private Object o。 } 4. public void doSomething() { 5. Object o = new Object()。 7. o = new Object()。 9. o = null。創(chuàng)建對象,第 5 和第 7 行,分別稱之為 A 和 B。在第 6 行結(jié)束時(shí),局部變量 o和全局變量 o 都引用 A。第八行結(jié)束時(shí), doSomethingElse 函數(shù)將全局變量 o 的引用改為 null,即 A 不在被變量引用,此時(shí) A 可被 GC 回收。 13. if (check = ()) { 14. ((check = 1) +, )。 17. } 18. } and the invocation: 21. test(four)。 23. test(to)。 QUESTION 31 Given: 1. interface A { public void aMethod()。 } 3. interface C extends A,B { public void cMethod()。 } class Gadget extends Widget { Spring s。 Sprocket s2。 Spring s2。 } class Widget extends Gadget{ Sprocket s。 Spring s2。 Sprocket s2。 QUESTION 33 A pany that makes Computer Assisted Design (CAD) software has, within its application, some utility classes that are used to perform 3D rendering tasks. The pany39。 key rendering algorithms, and has assigned a programmer to replace the old algorithm with the new algorithm. When the programmer begins researching the utility classes, she is happy to discover that the algorithm to be replaced exists in only one class. The programmer reviews that class39。s API. Once testing has begun, the programmer discovers that other classes that use the class she changed are no longer working properly. What design flaw is most likely the cause of these new bugs? A. Inheritance B. Tight coupling C. Low cohesion D. High cohesion E. Loose coupling F. Object immutability Answer: B 軟件工程要求高內(nèi)聚,低耦合。但是這里說 the programmer discovers that other classes that use the class she changed are no longer working properly. 所以肯定是沒有遵循這個(gè)原則,改變了一小部分,其他沒 動過的不能用了,說明耦合性太高了。 } D. class Man { private Dog bestFriend。 } F. class Man { private BestFrienddog。 33. public void addFive() { a += 5。 } 34. } 35. class Bar extends Foo { 36. public int a = 8。 (b )。 ()。 What is the result? A. b 3 B. b 8 C. b 13 D. f 3 E. f 8 F. f 13 G. Compilation fails. H. An exception is thrown at runtime. Answer: A 多態(tài)性, f 引用的是 Bar 類型的, ()。方法具有多態(tài)性,但是域沒有多態(tài)性, f 是 Foo 類型的,所以 是 Foo 中的。 } } 12. class Dog extends Animal { 13. public String noise() { return bark。 } 17. } ... 30. Animal animal = new Dog()。 32. (())。 QUESTION 37 Given: 1. class Super { 2. private int a。 } 4. } ... 11. class Sub extends Super { 12. public Sub(int a) { super(a)。 } 14. } Which two, independently, will allow Sub to pile? (Choose two.) A. Change line 2 to: public int a。 C. Change line 13 to: public Sub() { this(5)。 } E. Change line 13 to: public Sub() { super(a)。 }, Sub 類沒有域 a。 }調(diào)用 Sub 類的其它的構(gòu)造函數(shù),也可以 public Sub() { super(5)。 QUESTION 38 Given: 1. public class Base { 2. public static final String FOO = foo。 5. Sub s = new Sub()。 7. ()。 9. ()。 11. } } 12. class Sub extends Base {public static final String FOO=bar。 QUESTION 39 Given: 1. package geometry。 4. class InnerTriangle { 5. public int base。 7. } 8. } Which statement is true about the class of an object that can reference the variable base? A. It can be any class. B. No class has access to base. C. The class must belong to the geometry package. D. The class must be a subclass of the class Hypotenuse. Answer: C 考察修飾符的作用域, base 變量在類 InnerTriangle 里面,而類 InnerTriangle 的作用域是包可見性。publicprotecteddefaultprivate QUESTION 41 Which two code fragments are most likely to cause a StackOverflowError? (Choose two.) A. int []x = {1,2,3,4,5}。 y 6。 B. static int[] x = {7,6,5,4}。 x[4] = 3。 y 10。 D. void doOne(int x) { doTwo(x)。 } void doThree(int z) { doTwo(z)。 x 1000000000。 F. void counter(int i) { counter(++i)。 } 13. class B extends A { 14. public void process() throws IOException { 15. ()。 17. throw new IOException()。 } 21. catch (IOException e) { (Exception)。子類不可以拋出父類沒有的異常。 13. switch(x) { 14. case 2: 。 16. } 17. } 18. private void go2(int x) { assert (x 0)。 。 對于第 12 行, assert 不能檢測公共方法的參數(shù),違反了原則 4 15 行, assert 肯定會發(fā)生,不會回到之前的狀態(tài),違反了原則 5 18 行符合原則 2。 3. public static void main(String[] args) { 4. z: 5. for(int x = 2。 x++) { 6. if(x==3) continue。 8. o = o + x。 11. } 12. } What is the result? A. 2 B. 24 C. 234 D. 246 E. 2346 F. Compilation fails. Answer: B 考察 break。 13. if (str == null) { 14. (null)。 17. } else { 18. (some)。 14. boolean b1 = true。 16. 17. if ((x == 4) amp。 !b2 ) 18. (1 )。 20. if ((b2 = true) amp。 b1 ) 21. (3