J.VIII · Java 25 practice question

A library module declares `exports com.acme.api;` in its module declaration. What compile-time and run-time access does this grant to code in other modules?

Choose one answer
Check answer and explanation

Correct answer: Access to public and protected types in com.acme.api, along with their public and protected members

Explanation

Exporting a package grants other modules compile-time and run-time access to both public and protected types in that package, as well as the public and protected members of those types.

Common trap

It is easy to forget that protected types and protected members are also accessible (for example, to subclasses in other modules) when a package is exported. Exporting a package never bypasses standard access control for package-private or private declarations.

Source: JLS SE 25 §7.7.2. Exported and Opened Packages
Checked against the cited text on 2026-11-25.

Report an error in this question