【文章內(nèi)容簡(jiǎn)介】
類(lèi)型的變量是不變的, s并沒(méi)有變化。而 StringBuilder 的 append 方法, (one)。直接把字符串添加到sb 引用的 StringBuilder 對(duì)象上。 that the current directory is empty, and that the user has read and write permissions, and the following: 11. import .*。 12. public class DOS { 13. public static void main(String[] args) { 14. File dir = new File(dir)。 15. ()。 16. File f1 = new File(dir, )。 17. try { 18. ()。 19. } catch (IOException e) { 。 } 20. File newDir = new File(newDir)。 21. (newDir)。 22. } 23. } Which statement is true? A. Compilation fails. B. The file system has a new empty directory named dir. C. The file system has a new empty directory named newDir. D. The file system has a directory named dir, containing a file . E. The file system has a directory named newDir, containing a file . Answer: E 考察 包。 : 11. class Converter { 12. public static void main(String[] args) { 13. Integer i = args[0]。 14. int j = 12。 15. (It is + (j==i) + that j==i.)。 16. } 17. } What is the result when the programmer attempts to pile the code and run it with the mand java Converter 12? A. It is true that j==i. B. It is false that j==i. C. An exception is thrown at runtime. D. Compilation fails because of an error in line 13. Answer: D args 是一個(gè) String 類(lèi)型的數(shù)組,第 13 行應(yīng)該是 int i = (args[0])。 : 11. String test = Test A. Test B. Test C.。 12. // insert code here 13. String[] result = (regex)。 Which regular expression, inserted at line 12, correctly splits test into Test A, Test B, and Test C? A. String regex = 。 B. String regex = 。 C. String regex = .*。 D. String regex = \\s。 E. String regex = \\.\\s*。 F. String regex = \\w[ \.] +。 Answer: E 正則表達(dá)式, String regex = \\.\\s*。表示根據(jù)點(diǎn)( dot)和空格( space)來(lái)分割字符串。 : 5. import 。 6. import 。 21. DateFormat df。 22. Date date = new Date()。 23. // insert code here 24. String s = (date)。 Which code fragment, inserted at line 23, allows the code to pile? A. df = new DateFormat()。 B. df = ()。 C. df = ()。 D. df = ()。 E. df = ()。 Answer: E getInstance()返回一個(gè) DateFormat 類(lèi)型的對(duì)象, public static final DateFormat getInstance() Get a default date/time formatter that uses the SHORT style for both the date and the time. a class Repetition: 1. package utils。 2. 3. public class Repetition { 4. public static String twice(String s) { return s + s。 } 5. } and given another class Demo: 1. // insert code here 2. 3. public class Demo { 4. public static void main(String[] args) { 5. (twice(pizza))。 6. } 7. } Which code should be inserted at line 1 of to pile and run Demo to print pizzapizza? A. import utils.*。 B. static import utils.*。 C. import .*。 D. static import .*。 E. import ()。 F. import static 。 G. static import 。 Answer: F 靜態(tài)導(dǎo)入,可以導(dǎo)入類(lèi),類(lèi)中的靜態(tài)方法,靜態(tài)域。格式 import static ...... import static 。//導(dǎo)入 Repetition 類(lèi)中的 twice 靜態(tài)方法。 import static .*。//導(dǎo)入 Repetition 類(lèi)中的所有靜態(tài)方法和靜態(tài)域。 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。s CLASSPATH is set (at login time) to:/usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/*.jar What is a possible location for the file? A. /test/ B. /home/bob/ C. /test/games/ D. /usr/lib/games/ E. /home/bob/games/ F. inside jarfile /opt/java/lib/ (with a correct manifest) G. inside jarfile /home/bob/downloads/ (with a correct manifest) Answer: C classpath 命令會(huì)把路徑動(dòng)態(tài)設(shè)置成 /test 和 /home/bob/downloads/*.jar,只能在這兩個(gè)路徑里搜索 ,由于在運(yùn)行的時(shí)候 classpath 后面是 ,所以肯定是games 包里面的 Chess 文件。所以 C 可能正確。而 /home/bob/downloads/*.jar 這種寫(xiě)法無(wú)效,因?yàn)槿绻袃蓚€(gè) jar 包都存在 ,系統(tǒng)不知道是哪一個(gè)。 : 3. interface Animal { void makeNoise()。 } 4. class Horse implements Animal { 5. Long weight = 1200L。 6. public void makeNoise() { (whinny)。 } 7. } 8. public class Icelandic extends Horse { 9. public void makeNoise() { (vinny)。 } 10. public static void main(String[] args) { 11. Icelandic i1 = new Icelandic()。 12. Icelandic i2 = new Icelandic()。 13. Icelandic i3 = new Icelandic()。 14. i3 = i1。 i1 = i2。 i2 = null。 i3 = i1。 15. } 16. } When line 15 is reached, how many objects are eligible for the garbage collector?A. 0 B. 1 C. 2 D. 3 E. 4 F. 6 Answer: E 垃圾回收 GC。 我們假設(shè) 13 行結(jié)束的時(shí)候, i1 引用的對(duì)象叫 A, i2 引用的對(duì)象叫 B, i3 引用的對(duì)象叫 C。 現(xiàn)在考慮在 15 行的時(shí)候, i1 和 i3 都引用 B,而 i2 引用為 null,所以目前有 A 和 C 兩個(gè)對(duì)象沒(méi)有變量引用,所以這兩個(gè)對(duì)象是可以被回收的。注意, A, B 對(duì)象中含有 Long 類(lèi)型的對(duì)象,所以,一共有 4 個(gè)變量可以被回收。 the Exhibit button. Given the fullyqualified class names: Which graph represents the correct directory structure for a JAR file from which those classes can be used by the piler and JVM? A. Jar A B. Jar B C. Jar C D. Jar D E. Jar E Answer: A classes defined in two different files: 1. package util。 2. public class BitUtils { 3. private static void process(byte[] b) {} 4. } 1. package app。 2 . public class SomeApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256] 。 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) 。 B. (bytes) 。 C. (bytes) 。 D. (bytes) 。 E. import .*。 process(bytes) 。 F. SomeApp cannot use the process method in BitUtils. Answer: F private,根本就不能使用。 : 11. public class ItemTest { 12. private final int id。 13. public ItemTest(int id) { = id。 } 14. public void updateId(int newId) { id = newId。 } 15. 16. public static void main(String[] args) { 17. ItemTest fa = new ItemTest(42)。 18. (69)。 19. ()。 20. } 21. } What is the result?A. Compilation fails. B. An exception is thrown at runtime. C. The