Java OCA OCP Practice Question 1694

Question

Given the following directory structure:

/top
  |--- mypkg
        |--- pkg
              |--- A.java
              |--- B.java

Assume that the two files A.java and B.java contain the following code, respectively:

// Filename: A.java
package pkg;
class A { B b; }

// Filename: B.java
package pkg;
class B {...}

For which combinations of current directory and command is the compilation successful?

Select the two correct answers.

(a) Current directory: /top/mypkg
    Command: javac -cp .:pkg A.java/*from   w  w  w.jav a 2 s .  c o  m*/

(b) Current directory: /top/mypkg
    Command: javac -cp . pkg/A.java

(c) Current directory: /top/mypkg
    Command: javac -cp pkg A.java

(d)  Current directory: /top/mypkg
     Command: javac -cp .:pkg pkg/A.java

(e)  Current directory: /top/mypkg/pkg
     Command: javac A.java

(f)  Current directory: /top/mypkg/pkg
     Command: javac -cp . A.java


(b) and (d)

Note

In (a) and (c), class A cannot be found.

In (e) and (f), class B cannot be found -there is no package under the current directory /top/mypkg/pkg to search for class B.

Note that specifying pkg in the classpath in (d) is superfluous.

The parent directory of the package must be specified.




PreviousNext

Related