Java OCA OCP Practice Question 2477

Question

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

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

And the code :

package com.mypkg;  
public class Main {  
  public static void main(String[] args) {  
    System.out.println("big app");  
  }  
} 

Which will invoke Main? (Choose all that apply.)

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


D and F are correct.

Note

F will be a tiny bit slower than D, because the .: tells the JVM to look in the current directory (in this case bigApp), before looking in classes.

A, B, C, E, and G use incorrect syntax, which will keep the JVM from finding the .class file.




PreviousNext

Related