AP Computer Science A Practice Quiz: Wrapper Classes
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 10 questions to check your progress.
Question 1 of 10
All Questions (10)
A) The automatic conversion of a wrapper class object to its corresponding primitive type.
B) The automatic conversion of a primitive type to its corresponding object wrapper class.
C) The principle that Integer and Double objects cannot be changed after they are created.
D) The process of including the Integer class within the java.lang package.
Correct Answer: B
Autoboxing is the automatic conversion that the Java compiler makes between primitive types and their corresponding object wrapper classes, for example, from an int to an Integer.
A) Autoboxing
B) Unboxing
C) Immutability
D) Instantiation
Correct Answer: B
Unboxing is the automatic conversion from a wrapper class to its primitive type. In this case, the `Integer` object `myNum` is converted to the `int` primitive `primitiveNum`.
A) 20
B) 20.0
C) 15.0
D) A compile-time error occurs.
Correct Answer: B
The `Integer` `val1` is unboxed to the primitive `int` 20. The expression becomes `20 / 2.0 + 10`. Division by a double `2.0` results in a double `10.0`. Then, `10.0 + 10` results in `20.0`. This `double` primitive is then autoboxed into the `Double` object `result`.
A) The original Integer object holding the value 5 is modified to hold the value 10.
B) The code will cause a runtime error because arithmetic operations are not allowed on objects.
C) A new Integer object with the value 10 is created, and the reference `count` is updated to point to this new object.
D) The code will not compile because Integer objects are immutable.
Correct Answer: C
Integer objects are immutable. When `count + 5` is executed, `count` is unboxed to 5, the addition is performed resulting in 10, and then a new Integer object is created to hold the value 10 via autoboxing. The reference `count` is then assigned to this new object.
A) They have a method to compare two objects.
B) They are part of the java.lang package.
C) They consume more memory than their primitive counterparts.
D) They can be used in ArrayLists, while primitives cannot.
Correct Answer: B
The provided content explicitly states that 'The Integer class and Double class are part of the java.lang package.'
A) int x = 10;
B) Integer y = 20;
C) int z = y;
D) Double d = new Double(30.0);
Correct Answer: B
Autoboxing is the automatic conversion of a primitive type to its wrapper class. In the line `Integer y = 20;`, the primitive `int` literal `20` is automatically converted into an `Integer` object.
A) 25.0
B) 50.0
C) 25
D) A runtime error occurs.
Correct Answer: B
Double objects are immutable. Inside the `updateValue` method, `val / 2.0` creates a new Double object with the value 25.0. The local reference `val` is updated to point to this new object. However, the original reference `myDouble` in the calling scope is unchanged and still points to the original object with the value 50.0.
A) They are mutable.
B) They are immutable.
C) They require explicit casting for arithmetic.
D) They are located in the java.util package.
Correct Answer: B
The provided content explicitly states that 'An Integer object is immutable. A Double object is immutable.' This means their state cannot be changed after creation.
A) 37.5
B) 37
C) 38
D) A compile-time error because you cannot multiply an Integer by a Double.
Correct Answer: A
Due to unboxing, the `Integer` `a` is converted to `int` 15, and the `Double` `b` is converted to `double` 2.5. The expression becomes `15 * 2.5`. Because one of the operands is a double, the result is a double, `37.5`.
A) They can be used in arithmetic expressions without explicit conversion.
B) They are stored in a special memory area called the constant pool.
C) Operations that seem to change the object, like `i++`, result in the creation of a new object.
D) They are automatically converted from their primitive types by the compiler.
Correct Answer: C
Because an `Integer` object's value cannot be changed, any operation that appears to modify it must create a new object with the new value. The original object remains unchanged. Unboxing and autoboxing are the mechanisms that make this seamless, but the creation of a new object is the consequence of immutability.