Given the following three files:
2. package mypkg; 3. import mypkg.modules.Rectangle; 4. public class Main { 5. public static void main(String[] args){ 6. Rectangle lunarShape = new Rectangle(); 7. System.out.println(lunarShape); 8. } } //from www. j a v a2s. co m 2. package mypkg.modules; 3. public interface Shape { /* more code */ } 2. package mypkg.modules; 3. public class Rectangle implements Shape { /* more code */ }
And given that Shape.java and Rectangle.java were successfully compiled and the directory structure is shown below:
$ROOT |-- mypkg | |-- modules | |-- Rectangle.class |-- controls.jar | |-- mypkg | |-- modules | |-- Shape.class |-- Main.java
Which are correct about compiling and running the Main class from the $ROOT directory?
Choose all that apply.
A, C, and F are correct.
In order to successfully compile the Main class, you ONLY need the Rectangle class to be on the classpath, so A and C are correct.
F is correct, because in order to successfully run the Main class, the classpath should include BOTH the JAR file and the base location of the Main and Rectangle classes.
Here, the JAR file is required because the Rectangle class has to access the Shape class at runtime.
When specifying multiple locations for the classpath, each location should be separated with the ":" symbol, although in real life that character depends on the platform.