Given the following four Java file definitions:



package facades;

public interface Foo { }
package facades;

public interface Boo extends Foo { }
package org.domain;

// line n1

public class Woofy implements Boo, Foo { }
package org;

// line n2

public class Test {
    public static void main(String[] args) {
        Foo obj = new Woofy();
    }
}

Which set modifications enable the code to compile and run?

A.
At line n1, Insert:

import facades;

At line n2, insert:

import facades;
import org.domain;

B.
At line n1, Insert:

import facades.*;

At line n2, insert:

import facades.*;
import org.*;

C.
At line n1, Insert:

import facades.*;

At line n2, insert:

import facades.Boo;
import org.*;

D.
At line n1, Insert:

import facades.Foo, Boo;

At line n2, insert:

import org.domain.Woofy;

E.
At line n1, Insert:

import facades.*;

At line n2, insert:

import facades.*;
import org.domain.Woofy;

題解

import關鍵字可以引入類別或是介面,不是引入套件(package),因此選項A是錯誤的。

而選項B和選項C,需注意到「*」所指的是該套件下的所有類別或是介面,並不包含子套件。實際上也沒有在分子、母套件,只要套件名稱不同就是不同的套件。

選項D,語法錯誤了,不能使用「,」來分別引入不同的類別。

選項E才是正確的。