nerdexam
Oracle

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…

Java Platform Module System

Question

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?

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)
  • A
    84% (27)
  • B
    3% (1)
  • C
    9% (3)
  • D
    3% (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 (for ServiceLoader), 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 the part module, not "all other modules" as required.
  • D has the dependencies backwards: it requires com.vehicle (a package, not a module name) and exports part (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

#module declarations#exports directive#requires directive#module visibility

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice