Java OCA OCP Practice Question 2982

Question

Given:

2. package pack.clients;  
3. import pack.bing.MyClass;  
4. public class Client{  
5.   public static void main(String[] args){  
6.     MyClass b = new MyClass();  
7.     System.out.println(b.getMoney(2000L));  
8. } } 

And given that Client.

java resides in the $ROOT directory and is not yet compiled.

There is another class named pack.bing.MyClass, which has a method called getMoney(long) that returns a value.

MyClass class is compiled and deployed into a JAR file called pack.jar, as shown in the following directory structure.

$ROOT  
   |-- Client.java  
   |-- [pack.jar]  
              |-- pack  
                    |-- bing  
                             |-- MyClass.class 

Which are correct about compiling or running the Client class from the $ROOT directory?

(Choose all that apply.)

  • A. To compile, use javac -cp pack.jar -d . Client.java
  • B. To compile, use javac -cp pack.jar#pack.bing.MyClass -d . Client.java
  • C. To compile, use javac -cp * -d . Client.java
  • D. To run, use java -cp pack.jar pack.clients.Client
  • E. To run, use java -cp . -d pack.jar pack.clients.Client
  • F. To run, use java -cp . -cp pack.jar pack.clients.Client
  • G. To run, use java -cp .:pack.jar pack.clients.Client


A and G are correct.

Note

A is correct because it correctly specifies the classpath to pack.

jar and the destination directory.

G is correct because the classpath should include the JAR file and base location of the Client class.

Note: The symbol ":" is used for the path separation, although in real life that character depends on the platform.




PreviousNext

Related