1Z0-819 · Question #30
Given: /code/a/Test.java containing: package a; import b.Best; public class Test { public static void main(String[] args) { Best b = new Best(); } } and /code/b/Best.java containing: package b…
The correct answer is A. javac /code/a/Test.java. Option A is correct because javac automatically resolves and compiles imported dependencies when their source files can be found relative to the inferred source root. When you compile /code/a/Test.java, the compiler sees package a and infers /code as the root, then follows the…
Question
Options
- Ajavac /code/a/Test.java
- Bjavac /code/a/Test.java /code/b/Best.java
- Cjava /code/a/Test
- Djavac /code /code/a/Test.java /code/b/Best.java
- Ejavac /code/a/code/b/Best.java
How the community answered
(55 responses)- A71% (39)
- B2% (1)
- C16% (9)
- D7% (4)
- E4% (2)
Explanation
Option A is correct because javac automatically resolves and compiles imported dependencies when their source files can be found relative to the inferred source root. When you compile /code/a/Test.java, the compiler sees package a and infers /code as the root, then follows the import b.Best statement to find and compile /code/b/Best.java automatically - producing .class files for both.
B is wrong because explicitly listing both files is unnecessary; javac already discovers Best.java through the import, making the extra argument redundant and not the expected usage pattern. C is wrong because java is the JVM runtime command used to run bytecode, not javac which compiles it - a fundamental distinction the exam tests. D is wrong because javac does not accept a bare directory (/code) as a positional argument; to specify a source root you'd need the -sourcepath /code flag instead. E is wrong because the path /code/a/code/b/Best.java simply doesn't exist - it incorrectly nests the directory structure.
Memory tip: Think of javac as a smart compiler that "follows the imports" - you only need to point it at the entry-point file, and it will chase down dependencies automatically, much like a compiler tracking #include chains in C.
Topics
Community Discussion
No community discussion yet for this question.