J.VIII · Java 25 practice question

A developer adds `import module com.example.core;` to a compilation unit. Which types from `com.example.core` become available on demand?

Choose one answer
Check answer and explanation

Correct answer: All public top-level classes and interfaces in packages exported by com.example.core to the current module

Explanation

A single-module-import declaration brings in only the public top-level classes and interfaces from packages that the named module exports to the current module.

Common trap

Package-private types are never accessible across module boundaries, so a module import does not expose them. Module encapsulation still applies; packages that are not exported to the current module are not imported.

Source: JLS SE 25 §7.5.5. Single-Module-Import Declarations
Checked against the cited text on 2026-11-25.

Report an error in this question