Java OCA OCP Practice Question 3022

Question

Given the current directory is bigApp, and the directory structure:

bigApp  
    |-- classes  
             |-- Main.class  
             |-- com  
                   |-- Main.class  
                   |-- mypkg  
                                  |-- Main.class 

And the three files:

public class Main {  
  public static void main(String[] args) { System.out.println("classes"); }  
}  
public class Main {  
  public static void main(String[] args) { System.out.println("com"); }  
}  
public class Main {  
  public static void main(String[] args) { System.out.println("ws"); }  
} 

Have been compiled into the classes, com, and mypkg directories, respectively.

Which will produce the output "ws"? (Choose all that apply.)

  • A. java -cp mypkg:. Main
  • B. java -cp classes/com/mypkg Main
  • C. java -cp classes/com/mypkg:classes Main
  • D. java -cp classes:classes/com/mypkg Main
  • E. java -cp .:classes/com/mypkg:classes Main
  • F. java -cp .:classes/com:classes/com/mypkg Main


B, C, and E

Note

B, C, and E correctly use the classpath option ( -cp) to find the desired version of Main.class.

The ":" separates the various paths to search, and paths are searched in the order in which they appear in the command line.

A will not find any Main.class file.

D will find the "classes" version.

F will find the "com" version.




PreviousNext

Related