Java Generics, Enums, and Autoboxing Flashcards
6 cards from real SCJP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 Java Generics, Enums, and Autoboxing flashcards as text
What is the primary benefit of using generics in Java?
Answer: Type safety at compile time, eliminating the need for explicit casting
Generics allow type parameters to be specified at compile time, catching type errors early and eliminating the need for unsafe casts.
What is type erasure in Java generics?
Answer: Removing type parameter information at compile time so the bytecode uses raw types
Java implements generics through type erasure: type parameters are removed at compile time and replaced with their bounds (or Object), so no generic type info exists at runtime.
What does autoboxing in Java do?
Answer: Automatically converts primitive types to their wrapper class equivalents
Autoboxing is the automatic conversion of primitives (like `int`) to their wrapper classes (like `Integer`) when needed by the context.
Which of the following correctly declares a generic method in Java?
Answer: public T swap(T a, T b)
A generic method declares its type parameter `` before the return type: `public T methodName(...)`.
What is an enum in Java?
Answer: A special class that represents a group of named constants
An `enum` is a special Java class that defines a fixed set of named constants, with the ability to have fields, methods, and constructors.
What is the result of unboxing a null Integer in Java?
Answer: Throws NullPointerException
Unboxing a null wrapper (e.g., `Integer i = null; int x = i;`) throws a `NullPointerException` because null cannot be converted to a primitive.
How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy