第116題: |
Given: 11. public class Commander{ java -Dprop.custom=gobstopper Commander |
Which two, placed on line 13, will produce the output gobstopper? (Choose two.) A. System.load("prop.custom"); B. System.getenv("prop.custom"); C. System.property("prop.custom); D. System.getProperty("prop.custom"); E. System.getProperties().getProperty("prop.custom"); |
答案:DE |
題目範圍:System下的方法 |
解析: System.load方法可以傳入一個檔案位址,讓程式將指定檔案的內容加入函式庫中 System.getenv方法會回傳對應輸入的環境變數,例如你可以輸入"JAVA_HOME" System.property,沒有這個方法 System.getProperty會回傳在執行檔案時所定義的屬性 System.getProperties會回傳一個hashtable裡面包含很多系統資訊,詳細請上網搜尋 |
第117題: |
Given: 11. class Converter{ |
What is the result when the programmer attempts to compile the code and run it with the command 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. |
答案:D |
題目範圍:基本觀念 |
解析: 傳入的資料args型態是字串的陣列,必須經過轉換才能變成數字 Integer i = Integer.valueOf(args[0]); |
第118題: |
Given: 10. class Foo{ |
Which two statements are true? (Choose two.) A. Foo.beta() is a valid invocation of beta(). B. Foo.alpha() is a valid invocation of alpha(). C. Method beta() can directly call method alpha(). D. Method alpha() can directly call method beta(). |
答案:BC |
題目範圍:靜態方法 |
解析: 靜態方法可以直接指明被呼叫如:Foo.alpha() 一般方法就要建立實體才能呼叫如:new Foo().beta() 靜態方法中不可以呼叫一般方法;一般方法可以呼叫靜態方法 |
第119題: |
Given: 11. public static void main(String[] args){ |
What is the result? A. null B. zero C. some D. Compilation fails. E. An exception is thrown at runtime. |
答案:D |
題目範圍:基本觀念 |
解析: 這題粗心的話可是會被騙… 第二個else後面少了if,所以錯了 如果修正的話,結果會是some |
第120題: |
Given: 1. public class GC{ |
When the doSomething method is called, after which line does the Object created in line 5 become available for garbage collection? A. Line 5 B. Line 6 C. Line 7 D. Line 8 E. Line 9 F. Line 10 |
答案:D |
題目範圍:物件與指標觀念 |
解析: 這提是指標的觀念 第5行執行後生出了一個物件,下面用*代表這個物件,方法中的o→* 第6行,doSomethingElse的obj→*然後類別中的o→* doSomethingElse方法執行完之後,obj就不再被使用 第7行,新生出一個物件,下面用⊕代表這個新的物件,方法中的o→⊕ 第8行,doSomethingElse的obj→null然後類別中的o→null 到目前為止,終於沒有任何一個指標指向*,*被列入回收清單 第9行,方法的o→null,沒有任何一個指標指向⊕,⊕被列入回收清單 第10行,沒有動作 |
留言列表