2009年2月13日 星期五

第116題

Given:
11. public class Commander{
12. public static void main(String[] args){
13. String myProp = /* insert code here */
14. System.out.println(myProp);
15. }
16. }
and the command line:
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
參考:8-4 main()方法的參數傳遞與系統屬性設定

--------------------------------------------------

-D 代表設定系統屬性. 屬性名稱是 prop.custom, 對應值是 gobstopper.
所以用getProperty("prop.custom").
或是 用 getProperties() 物件 裡面的 getProperty("prop.custom")

沒有留言:

張貼留言