Converting a primitive type data into its corresponding wrapper class object…

2014

Converting a primitive type data into its corresponding wrapper class object instance is called

  1. A.

    Boxing

  2. B.

    Wrapping

  3. C.

    Instantiation

  4. D.

    Autoboxing

Attempted by 362 students.

Show answer & explanation

Correct answer: D

Answer: Autoboxing.

Explanation: Autoboxing is the automatic conversion performed by the compiler that converts a primitive value into its corresponding wrapper class object (for example, converting an int to an Integer). This feature was introduced in Java 5 to reduce boilerplate code.

Distinction to remember: Boxing is the general term for converting a primitive to a wrapper class (which can be done manually), while autoboxing refers specifically to the compiler doing it automatically.

  • Manual boxing example: Integer boxed = Integer.valueOf(5);

  • Autoboxing example: Integer auto = 5; // compiler automatically converts 5 to an Integer

Also note: The opposite process (converting a wrapper object back to a primitive) is called unboxing (or auto-unboxing when done automatically).

Explore the full course: Nta Ugc Net Paper 2

Loading lesson…