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.11.2. Generic Interface
This section
Practice test
7 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 is a Generic Interface in Java?
Hint
Think about flexibility in programming.
- 2.
Create a Generic Interface named 'Storage
' with a method 'store(T item)'. Hint
Remember to include the type parameter.
- 3.
What does a Generic Interface allow in Java?
- A. Only integer types can be used
- B. Flexibility to use various data types
- C. It makes all types unsafe
Hint
Think about why generics were introduced.
- 4.
Is it true that generic interfaces help in preventing type errors?
- True
- False
Hint
Consider the benefits of using generics.
- 5.
Design and implement a Generic Interface called 'Processor
' with a method 'process(T data)'. Then implement this interface in a class for processing Strings. Hint
Focus on ensuring the 'process' method works with the specified type.
- 6.
Create a class 'NumberStorage' that implements the 'DataStore
' interface ensuring it only accepts Numbers. Discuss how type safety is achieved. Hint
Use the bounds of generics to limit the types.
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
1 more question 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