Enrol to start learning
Reading is open to everyone. Enrolling is free, and it is what unlocks the audio lessons, practice tests and progress tracking.
15.10.2. Upper Bounded Wildcards
This section
Practice test
10 questions on this section. Wrong answers show you what to read again.
Sign up to take itWhole chapter
Revision test
Mixed questions from across the chapter. Your answers get marked.
Sign up to take itQuick
Flashcard drill
2 cards from this lesson. Good the night before a test.
Try these first
- 1.
What does
List<? extends Number>signify?Hint
Think about what types can be included in the Number class hierarchy.
- 2.
Why are upper bounded wildcards used?
Hint
Recall how they restrict types to a specific upper limit.
- 3.
What does
<? extends T>mean in Java?- Allows writing to any object of type T.
- Allows reading any object of type T or its subclasses.
- Blocks the use of any subclass of T.
Hint
Think about how generics enforce constraints.
- 4.
True or False: A List of type
List<? extends Animal>can accept a List of Dogs.- True
- False
Hint
Consider the class hierarchy.
- 5.
Implement a generic method that calculates the sum of a list containing any number subclasses. Ensure type safety through upper bounded wildcards.
Hint
Student should focus on using `doubleValue()` on the Number class.
- 6.
Create a class that manages a collection of objects from various subclasses of a parent class, ensuring it utilizes upper bounded wildcards when retrieving items.
Hint
Pay attention to the class definition and method parameter signatures.
Exercises
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
4 more questions available
Enrol freeQuiz
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
Get your answers marked and your progress tracked
Enrol freeChallenge Problems
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting