Given these files:// lib/com/shop/api/Cart.java
package com.shop.api;
public class Cart { }
// lib/com/shop/api/spi/Pricing.java
package com.shop.api.spi;
public interface Pricing { }
// app/module-info.java
module app {
requires lib;
}
// app/app/Main.java
package app;
import com.shop.api.Cart;
import com.shop.api.spi.Pricing;
public class Main {
public static void main(String[] args) {
Cart c = new Cart();
Pricing p = null;
System.out.println("ok");
}
}Which two declarations of module lib let both modules compile so that app prints ok? (Select TWO.)
Choose TWO.
An exports directive names exactly one package. Subpackages are separate packages, and opens is a run-time reflection grant, not a compile-time export.
Java has no package hierarchy as far as modules are concerned: com.shop.api.spi is unrelated to com.shop.api, so it needs its own exports directive. The plain module with two exports works, and so does the open module with the same two exports, because open adds deep reflection on top without removing exports. The wildcard is not legal syntax, the single export leaves Pricing invisible, and opens does not help javac.
- Identify the packages app imports from: com.shop.api and com.shop.api.spi.
- Check that each is named by its own exports directive.
- Reject syntax that module declarations do not have, such as a wildcard.
- Remember that opens affects reflection at run time, not compilation.
Exam tip: One exports directive per package; subpackages are never exported implicitly.
Java Modules, Services and Module Imports (1Z0-831) — the lesson that teaches this.