1Z0-819 · Question #14
Module vehicle depends on module part and makes its com.vehicle package available for all other modules. Which module-info.java declaration meets the requirement?
The correct answer is A. module vehicle { requires part; exports com.vehicle; }. Option A is correct because it uses requires to declare a dependency on the part module, and exports to make the com.vehicle package accessible to all other modules - exactly what the question asks for. Why the distractors fail: B uses uses, which is a service consumer…
Question
Options
- Amodule vehicle { requires part; exports com.vehicle; }
- Bmodule vehicle { requires part; uses com.vehicle; }
- Cmodule vehicle { requires part; exports com.vehicle to part; }
- Dmodule vehicle { requires com.vehicle; exports part; }
How the community answered
(32 responses)- A84% (27)
- B3% (1)
- C9% (3)
- D3% (1)
Explanation
Option A is correct because it uses requires to declare a dependency on the part module, and exports to make the com.vehicle package accessible to all other modules - exactly what the question asks for.
Why the distractors fail:
- B uses
uses, which is a service consumer directive (forServiceLoader), not a package export - it has nothing to do with making a package available to other modules. - C uses
exports com.vehicle to part, which is a qualified export - it restricts access to only thepartmodule, not "all other modules" as required. - D has the dependencies backwards: it requires
com.vehicle(a package, not a module name) and exportspart(a module name, not a package) - both are semantically inverted.
Memory tip: Think of the module-info.java keywords by their direction - requires points inward (what you need from others) and exports points outward (what you give to others). If you see to after exports, it's a restricted handshake, not an open door.
Topics
Community Discussion
No community discussion yet for this question.