Search⌘ K
AI Features

Quiz: Generics and Type Safety

Tests your understanding of generic classes, methods, wildcards, comparators, and collection algorithms through a comprehensive quiz.

We'll cover the following...
Technical Quiz
1.

Why does this code fail to compile?

Box<Integer> numberBox = new Box<>();
numberBox.set("Fifty");
A.

The set method expects an Object, so the code is valid but unsafe.

B.

The compiler enforces that numberBox only accepts Integer values.

C.

Generics cannot handle wrapper classes like Integer, only primitives.

D.

The diamond operator <> was omitted on the left side of the assignment.


1 / 10
...