0
0
Javaprogramming~15 mins

Unboxing in Java - Cheat Sheet & Quick Revision

Choose your learning style8 modes available
overviewRecall & Review
beginner
What is unboxing in Java?
Unboxing is the automatic conversion of an object of a wrapper class (like Integer) to its corresponding primitive type (like int).
touch_appClick to reveal answer
beginner
Which of these is an example of unboxing?
Integer num = 10;
int n = num;
Assigning an Integer object to an int variable automatically converts the Integer to int. This is unboxing.
touch_appClick to reveal answer
beginner
Why is unboxing useful in Java?
Unboxing lets you use wrapper objects like primitive types without manually converting them, making code simpler and easier to read.
touch_appClick to reveal answer
intermediate
What happens if you unbox a null wrapper object?
Unboxing a null wrapper object causes a NullPointerException because there is no primitive value to convert.
touch_appClick to reveal answer
beginner
Which wrapper classes support unboxing in Java?
All wrapper classes like Integer, Double, Boolean, Character, Byte, Short, Long, and Float support unboxing to their respective primitive types.
touch_appClick to reveal answer
What does unboxing do in Java?
AConverts a wrapper object to a primitive type automatically
BConverts a primitive type to a wrapper object automatically
CConverts a String to an int
DConverts an int to a String
What will happen if you try to unbox a null Integer object?
AIt returns 0
BIt returns null
CIt throws a NullPointerException
DIt converts to false
Which of these is an example of unboxing?
AInteger n = 5;
Bint n = new Integer(5);
Cint n = Integer.valueOf(5);
Dint n = new Integer(5).intValue();
Which wrapper class does NOT support unboxing?
AString
BDouble
CInteger
DBoolean
Unboxing helps to:
AMake code more complex
BConvert primitives to objects
CPrevent NullPointerExceptions
DAvoid manual conversion from wrapper to primitive
Explain what unboxing is and give a simple Java example.
What error can occur during unboxing and why?