1Z0-829 Working with Arrays and Collections Practice Question
Which THREE of the following variable declarations are valid in Java 17?
⚠ Common exam trap
A common mix-up: candidates confuse generic invariance with array covariance, mistakenly thinking `List<Object>` can hold a `List<String>` (like `Object[]` can hold `String[]`), or they incorrectly assume wildcards can be used in instantiation expressions like `new ArrayList<?>()`.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
List<?> list = new ArrayList<String>();
`List<?>` is a wildcard type that can hold any type, and `new ArrayList<String>()` creates an `ArrayList` of a specific type (`String`). The wildcard `?` acts as a type-safe placeholder, allowing the assignment of a concrete parameterized type to an unbounded wildcard reference. This is valid because the wildcard represents an unknown type, and the list is read-only in terms of type safety (you cannot add elements except `null`).
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
List<?> list = new ArrayList<String>();
Why this is correct
Correct: wildcard captures any type.
- ✗
List<Object> list = new ArrayList<String>();
Why it's wrong here
Invalid: generics are invariant; List<String> is not a subtype of List<Object>.
- ✓
List<? super Integer> list = new ArrayList<Number>();
Why this is correct
Correct: Number is a supertype of Integer, so this is valid.
- ✓
List<? extends Number> list = new ArrayList<Integer>();
Why this is correct
Correct: Integer extends Number, so this assignment is valid.
- ✗
List<?> list = new ArrayList<?>();
Why it's wrong here
Invalid: cannot create an ArrayList of wildcard type; the type argument must be a concrete type.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-829 question from scratch — 513 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.