J.VIII · Java 25 practice question

When a compilation unit includes a single-type-import declaration `import TypeName;`, where does the imported type become available under its simple name?

Choose one answer
Check answer and explanation

Correct answer: In the module, class, and interface declarations of that compilation unit

Explanation

A single-type-import declaration makes the imported class or interface available under its simple name throughout the module, class, and interface declarations of the compilation unit where it appears.

Common trap

Module declarations (such as module-info.java) can also use single-type-import declarations, for example to shorten service type names in uses or provides directives. Import declarations are scoped strictly to the compilation unit in which they appear, not to the entire package.

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

Report an error in this question