Given the following two files containing Main.java and Square.java:
2. package ec.mypkg; 3. public class Main{} 4. class Shape{} 2. package ec.mypkg; 3. public class Square{} 4. class Rectangle{}
And if those files are located in the following directory structure:
$ROOT |-- Main.java |-- Square.java |-- checker |-- dira |-- dirb
And the following commands are executed, in order, from the ROOT directory:
javac Main.java -cp checker/dira -d checker/dirb javac Square.java -cp checker/dirb -d checker/dira jar -cf checker/dira/a.jar checker
A new JAR file is created after executing the above commands.
Which of the following files will exist inside that JAR file? (Choose all that apply.).
A. [JAR]/dira/ec/mypkg/Rectangle.class B. [JAR]/checker/dirb/ec/mypkg/Shape.class C. [JAR]/dirb/ec/mypkg/Rectangle.class D. [JAR]/checker/dira/ec/mypkg/Shape.class E. [JAR]/dira/a.jar F. [JAR]/checker/dira/a.jar
B is correct.
When using the jar command with -cf switches, the given source directory will be copied to the JAR file together with its subdirectories and files.
D is incorrect because the -d switch is used to specify the destination directory, so there will be no impact on the classpath directory during compilation or JAR file creation.
F is incorrect because there was NO such JAR file before the creation of the new JAR file.
A, C, and E are incorrect based on the above.