第九十一題: |
A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wants to execute the main method of Poker on a UNIX system using the command: java games.cards.Poker What allows the user to do this? A. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java B. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/*.jar C. Put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/Poker.jar D. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java E. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/*.jar F. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/Poker.jar |
答案:C |
題目範圍:編譯指令 |
解析: UNIX在指定class path的方法與windows一樣,指定classpath為要關聯的jar檔案 這裡的路徑/stuff/java只是一個例子,並非絕對 |
第九十二題: |
Given a correctly compiled class whose source code is: package com.sun.sjcp; |
Assume that the class file is located in /foo/com/sun/sjcp/, the current directory is /foo/, and that the classpath contains "." (current directory). Which command line correctly runs Commander? A. java Commander B. java com.sun.sjcp.Commander C. java com/sun/sjcp/Commander D. java -cp com.sun.sjcp Commander E. java -cp com/sun/sjcp Commander |
答案:B |
題目範圍:編譯指令、執行指令 |
解析: 執行時,下層資料夾使用"."隔開,而非斜線 |
第九十三題: |
Given: 10. class Nav { |
Which code, inserted at line 14, allows the Sprite class to compile? A. Direction d = NORTH; B. Nav.Direction d = NORTH; C. Direction d = Direction.NORTH; D. Nav.Direction d = Nav.Direction.NORTH; |
答案:D |
題目範圍:列舉(enum) |
解析: 列舉適合用來取代定義的常數,像是Monday=0,Theusday=1等等 詳細資訊待補 |
第九十四題: |
Given: 11. public class Rainbow { |
Which code fragment inserted at line 19, allows the Rainbow class to compile? A. MyColor skyColor = BLUE; B. MyColor treeColor = MyColor.GREEN; C. if(RED.getRGB() < BLUE.getRGB()){} D. Compilation fails due to other error(s) in the code. E. MyColor purple = new MyColor(0xff00ff); |
答案:B |
題目範圍:列舉(enum) |
解析: A:應改為MyColor skyColor = MyColor.BLUE; C:應改為if(MyColor.RED.getRGB() < MyColor.BLUE.getRGB()){} E:enum不是類別,無法實體化為物件,更不能傳入建構子參數 |
第九十五題: |
Given: 1. interface TestA { |
What is the result? A. test B. null C. An exception is thrown at runtime. D. Compilation fails because of an error in line 1. E. Compilation fails because of an error in line 4. F. Compilation fails because of an error in line 5. |
答案:A |
題目範圍:innerclass、interface |
解析: 如果你要將一個物件以println方法顯示在螢幕上,他就會呼叫物件中的toString方法 在這裡,我們在實體化TestA的同時重新定義了toString方法,這是一種innerclass的寫法 |