第九十一題:

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

答案:

題目範圍:編譯指令

解析:

UNIX在指定class path的方法與windows一樣,指定classpath為要關聯的jar檔案

這裡的路徑/stuff/java只是一個例子,並非絕對

 

第九十二題:

Given a correctly compiled class whose source code is:

package com.sun.sjcp;

public class Commander {
    public static void main(String[] args) {
        // more code here
    }

}

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

答案:

題目範圍:編譯指令、執行指令

解析:

執行時,下層資料夾使用"."隔開,而非斜線

 

第九十三題:

Given:

10.    class Nav {
11.        public enum Direction {
            NORTH, SOUTH, EAST, WEST
        }

12.    }

13.    public class Sprite {
14.        // insert code here
15.    }

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;

答案:

題目範圍:列舉(enum)

解析:

列舉適合用來取代定義的常數,像是Monday=0,Theusday=1等等

詳細資訊待補

 

第九十四題:

Given:

11.     public class Rainbow {
1
2
.         public enum MyColor {
1
3
.             RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff);
1
4
.             private final int rgb;

1
5
.             MyColor(int rgb) {
                this.rgb = rgb;
            }

1
6
.             public int getRGB() {
                return rgb;
            }
17
.         }

1
8
.         public static void main(String[] args) {
1
9
.             // insert code here
20
.         }

2
1.     }

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);

答案:

題目範圍:列舉(enum)

解析:

A:應改為MyColor skyColor = MyColor.BLUE;

C:應改為if(MyColor.RED.getRGB() < MyColor.BLUE.getRGB()){}

E:enum不是類別,無法實體化為物件,更不能傳入建構子參數

 

第九十五題:

Given:

1.     interface TestA {
        String toString();
    }

2.     public class Test {
3.         public static void main(String[] args) {
4.             System.out.println(new TestA() {
5.                 public String toString() {
                    return "test";
                }
6.             });
7.         }
8.     }

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.

答案:

題目範圍:innerclassinterface

解析:

如果你要將一個物件以println方法顯示在螢幕上,他就會呼叫物件中的toString方法

在這裡,我們在實體化TestA的同時重新定義了toString方法,這是一種innerclass的寫法

arrow
arrow
    全站熱搜

    yaya741228 發表在 痞客邦 留言(1) 人氣()