• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar

JavaTutorOnline

1-on-1 Online Java Training by a Senior Software Engineer

  • Home
  • AP CSA
    • FRQ Practice
      • Arrays
      • ArrayList
      • Strings
      • 2D Arrays
    • MCQ Practice
      • Booleans
      • Iteration
      • Arrays
      • View all Units
  • Courses
  • Tutorials
    • Java
    • Servlets
    • Struts
    • Spring
    • Webservice
  • FAQ
  • Testimonials
  • Blog
  • CONTACT US

AP CSA Wrapper Classes & Autoboxing Practice MCQs

Home » AP CSA MCQ » Unit 2

AP CSA Practice: Wrapper Classes & Autoboxing

Topic 2.9 ⏱️ 10 Min Practice ✅ Updated for 2027 Exam

Java is an object-oriented language, but it also uses primitive types (like int and double) for performance. To bridge this gap, Java provides wrapper classes (`Integer` and `Double`) that wrap primitive values inside an object wrapper.

Key Concepts to Remember Before You Start:

  • Autoboxing: The automatic conversion that Java makes from a primitive type to its corresponding wrapper object (e.g., assigning an int to an Integer variable).
  • Unboxing: The automatic conversion from a wrapper object back to a primitive type (e.g., passing an Integer object into a math operation expecting an int).
  • The Wrapper Comparison Trap: Just like Strings, wrapper objects must be compared using .equals() rather than ==, because == checks memory addresses.

Test your knowledge with these 10 practice questions. Click “View Answer & Explanation” to see how autoboxing behaves behind the scenes.

Topic 2.9 Practice

Question 1 of 10 | Score: 0
1. Which of the following wrapper classes corresponds to the primitive type int in Java?
Correct Answer: C The wrapper class for the primitive int is capitalized as Integer. Similarly, the wrapper class for double is Double, and boolean is Boolean.
2. Which of the following best defines autoboxing in Java?
Correct Answer: B Autoboxing is the automatic wrapping of a primitive value (like an int) into an object of its wrapper class (like an Integer) without requiring explicit constructor calls.
3. Consider the following code segment:
Integer num = 25;
int x = num;
System.out.println(x);
What term describes the conversion happening on the second line (int x = num;)?
Correct Answer: B Unboxing is the automatic conversion of a wrapper object (Integer) back into its primitive equivalent (int) by the Java compiler.
4. Consider the following code segment:
Integer val1 = 100;
Integer val2 = 100;
System.out.println(val1 == val2);
What is printed as a result of executing this code? (Note: Java caches Integer objects between -128 and 127).
Correct Answer: A Due to Java’s internal memory caching for small Integer values (-128 to 127), autoboxing the value 100 points both variables to the exact same cached object in memory. Therefore, val1 == val2 evaluates to true. (Though best practice on the AP exam is always to use .equals() for objects).
5. What is printed by the following code segment?
Integer a = 1000;
Integer b = 1000;
System.out.println(a == b);
Correct Answer: B Because 1000 is outside Java’s small integer cache range (-128 to 127), autoboxing creates two separate distinct objects in memory. The == operator compares memory references, which are different, returning false. This highlights why comparing wrapper objects with == is dangerous.
6. Consider the following code segment:
Integer n = null;
int result = n;
System.out.println(result);
What happens when this code is executed?
Correct Answer: C When Java attempts to unbox a null Integer object into a primitive int (int result = n;), it tries to retrieve a primitive value from a non-existent object. This instantly throws a NullPointerException.
7. What is output by the following code segment?
Double d = 5.5;
double sum = d + 2.0;
System.out.println(sum);
Correct Answer: B Because the addition operator + expects numeric primitive values, Java automatically unboxes the Double object d into a primitive double (5.5). It then performs standard mathematical addition with 2.0, resulting in 7.5.
8. Which of the following correctly describes the relationship between wrapper classes and methods?
Correct Answer: B Wrapper classes provide helpful static constants and methods. For example, Integer.MAX_VALUE and Integer.MIN_VALUE are frequently tested on the AP exam for algorithm boundaries.
9. Consider the following code segment:
Integer x = 5;
Integer y = 5;
System.out.println(x.equals(y));
What is printed as a result of executing this code?
Correct Answer: A The .equals() method on wrapper classes compares the actual numerical value stored inside the object rather than their memory addresses. Since both objects represent the value 5, x.equals(y) returns true.
10. Why are wrapper classes required when working with Java’s ArrayList data structure (Unit 7)?
Correct Answer: B Java data structures like ArrayList are designed to hold objects, not raw primitives. Wrapper classes allow you to store integers and doubles inside collections seamlessly thanks to automatic autoboxing.

Unit 2.9 Practice Complete!

0 / 10

The Golden Rule of Wrapper Classes

Just like with Strings, never use == to compare two Integer or Double objects unless you are intentionally checking memory addresses. Always use .equals() to compare their numerical values safely.

Ready for the Final Challenge?

You have successfully built and reviewed all four sub-topics of Unit 2: String Methods, the Math class, Object References, and Wrapper Classes. You are now fully prepared for the comprehensive exam test.

Test your complete mastery by taking the Unit 2 Cumulative Mock Exam!

← Back to Unit 2 Using Objects Hub
Next: Unit 2 Mock Exam →

Primary Sidebar

Mr Chinmay

Chinmay Patel
Book a Demo Class

Phone & Whatsapp +919853166385
javatution@gmail.com

Recent Posts

  • Learn Java in One Day: 10-Hour 1-on-1 Crash Course | JavaTutorOnline
  • Constructor in Java: Examples, Types & Constructor Overloading
  • Important Interview Questions on Java Multithreading
  • React Spring Boot Web Services React Integration
  • Spring Boot RESTful Web Services Example
  • Top Spring MVC Interview Questions and Answers for Developers
  • Top Spring Core Interview Questions and Answers for Developers
  • Host Java Web Apps for Free on Mobile with Tomcat and Termux
  • How to Deploy Java Web Application on Aws EC2 with Elastic IP
  • Simple Jsp Servlet Jdbc User Registration using Tomcat Mysql and Eclipse

Additional Resources

  • AP Computer Science A Summer Prep
Copyright © 2026 JavaTutorOnline