Question 1
Why should collections use generics?
To allow all data types
To ensure type safety
To make them faster
To reduce memory
Question 2
What happens when we use raw types in collections?
Type safety is ensured
Compilation error
Possible ClassCastException
Generics are enforced
Question 3
What does type erasure mean in Java generics?
Types removed at runtime
Generics used at runtime
Types checked at runtime
Compiler adds extra type
Question 4
Which is a valid declaration for a generic List?
List list = new ArrayList();
List
List
List
Question 5
What does the following code produce?
List<String> list = new ArrayList<>();
list.add("Java");
String val = list.get(0);
Compilation error
Runtime error
Java
null
Question 6
Which of the following is NOT true about generics with collections?
Prevents runtime casting
Enforces compile-time safety
Increases chance of ClassCastException
Makes code cleaner
There are 6 questions to complete.