1Z0-830 practice question 2 of 25

Which of the following statements is TRUE about modules in Java SE 21?

Full set: 116 questions
Answer options
A:

A. Modules can access all public classes from any other module by default.

B:

B. Modules require explicit declaration of dependencies on other modules.

Correct answer
C:

C. Reflection can be used to bypass module boundaries and access private members.

D:

D. Services and providers are not related to the modular system in Java.

Correct Answer:
B. B. Modules require explicit declaration of dependencies on other modules.
Explanation

The Java Platform Module System (JPMS), introduced in Java 9, enforces strong encapsulation and reliable configuration. A core principle is that modules must explicitly declare their dependencies. A module uses the requires directive in its module-info.java descriptor to state its dependency on another module. Without this declaration, the depending module cannot access any types from the other module at compile time or runtime, even if those types are public and exported.

Why Incorrect

A. This describes the pre-module "classpath hell" behavior. By default, modules cannot access types from other modules; packages must be explicitly exported via the exports directive.
C. Strong encapsulation in modules prevents reflective access to non-public members of a package by default. A package must be explicitly opened via the opens directive to permit this.
D. Services are a key feature of the module system, supported by the uses and provides...with directives in the module descriptor to enable a robust service-provider mechanism.

References

1. Oracle Corporation. (2023). The State of the Module System. JEP 454: Java Platform, Standard Edition 21. Retrieved from https://openjdk.org/jeps/261. (See section "Reliable configuration" which details the requires clause.)

2. Reinhold, M. (2017). The State of the Module System. Oracle. Retrieved from https://cr.openjdk.org/~mr/jigsaw/spec/sotms-2017-09-01.html#reliable-configuration. (The requires directive is fundamental to establishing the module graph.)

Scroll to Top