Question 1
A developer imports the whole of java.base with a module import declaration and adds an on-demand import for java.awt. What is the result of compiling and running this program? ```java import module java.base; import java.awt.*; public class Main { public static void main(String[] args) { List<String> items = new ArrayList<>(); items.add("go"); System.out.println(items.size()); } } ```
A. 1
Assumes the module import wins so the name means the collection type; a type-import-on-demand shadows a module import, so the name means the AWT type.
B. Compilation failsCorrect answer
The on-demand import of the AWT package shadows the module import, so the name resolves to the non-generic AWT type, and the parameterised use fails to compile.
C. 0
Assumes the compiler prefers the generic candidate and the program runs; the name resolves to the non-generic AWT type, a compile error.
D. Throws ClassCastException
Assumes a runtime cast failure; the conflict is a compile-time shadowing error, so nothing runs.
Explanation
This is shadowing, not ambiguity: a type-import-on-demand declaration shadows a same-named type brought in by a module import declaration, which sits lowest in import precedence. So the simple name resolves to the AWT type, and using it with type arguments, since that type is not generic, is a compile-time error. A single-type import would shadow both and select the intended type.