第五十六題: |
Given: 5. class Building{} |
Which is true? A. if line 10 is removed, the compilation succeeds. |
答案:C |
題目範圍:物件觀念、強制型態轉換 |
解析: 從子代轉為父代可以不需要強制型態轉換,例如筆電是個計算機 這題的強制型態轉換即使成功通過編譯,但是執行時依然會出現錯誤 Exception in thread "main" java.lang.ClassCastException: Building cannot be cast to Barn at Barn.main |
第五十七題: |
Given: 21. class Money{ |
What is the result? A. Canada |
答案:E |
題目範圍:物件觀念 |
解析: 如果變數被標記為private,即使用super去呼叫也不行 這題如果將變數的private拿掉,執行結果會是Canada Canada |
第五十八題: |
Given: 10. interface Foo{} 11. class Alpha implements Foo{} 12. class Beta extends Alpha{} 13. class Delta extends Beta{ 14. public static void main(String[] args){ 15. Beta x = new Beta(); 16. //insert code here 17. } 18. } |
Which code, inserted at line 16, will cause a java.lang.ClassCastException? A. Alpha a = x; |
答案:B |
題目範圍:物件觀念 |
解析: 如果直接把父代的物件轉型為子代的物件,這樣就會出現錯誤 要確認物件是否允許轉換為某型態,可以用instanceof
關鍵字來判斷 |
第五十九題: |
Given the following directory structure: bigProject And the following command line invocation: javac –d classes source/Utils.java |
Assume the current directory is bigProject, what it the result? A. If the compile is successful, Utils.class is added to the source directory. |
答案:C |
題目範圍:編譯指令 |
解析: javac –d 這個指令是指定要放編譯後檔案的目錄,用法如下: |
第六十題: |
Given: 1. package com.company.application; |
Which two java commands entered at the command line will run MainClass? (Choose two.) A. java MainClass if run from the /apps directory B. java com.company.application.MainClass if run from the /apps directory C. java -classpath /apps com.company.application.MainClass if run from any directory D. java-classpath . MainClass if run from the /apps/com/company/application directory E. java -classpath /apps/com/company/application:. MainClass if run from the /apps directory F. java com.company.application.MainClass if run from the /apps/com/company/application directory |
答案:BC |
題目範圍:編譯指令 |
解析: 執行時,路徑的使用方法 可以從任意地方指定絕對路徑,或是已經在路徑上,指定相對位置 |
留言列表