In Java, which of the following is an example of autounboxing?
A. `String text = "Hello";`
B. `int value = Integer.parseInt("42");`
C. `Double result = 3.14;`
D. None of These
Answer: Option D
Solution (By Examveda Team)
Autounboxing in Java refers to the automatic conversion of a wrapper class object to its corresponding primitive type.For example, converting an Integer object to an int, or a Double object to a double.
Let's examine the options:
Option A: String text = "Hello"; — This is just assigning a String literal to a String variable, not related to autounboxing.
Option B: int value = Integer.parseInt("42"); — This parses a String to a primitive int, but it does not involve autounboxing because no wrapper object is involved.
Option C: Double result = 3.14; — This is an example of autoboxing (primitive to wrapper), not autounboxing.
Since none of the options demonstrate converting a wrapper object to a primitive type, the correct answer is None of These.
Join The Discussion
Comments (1)
A. The automatic conversion of primitive types to their corresponding wrapper classes
B. The process of creating a new box
C. A feature for manually converting wrapper classes to primitive types
D. A feature for boxing objects
Which primitive type corresponds to the `Integer` wrapper class in Java?
A. `char`
B. `boolean`
C. `float`
D. `int`
What is the primary benefit of autoboxing in Java?
A. It improves memory management
B. It reduces code complexity
C. It simplifies code by automatically converting between primitive types and their corresponding wrapper classes
D. It speeds up code execution
In Java, which classes are used for autoboxing and unboxing operations?
A. Exception classes (e.g., `RuntimeException`)
B. Wrapper classes (e.g., `Integer`, `Double`)
C. Collection classes (e.g., `ArrayList`, `HashMap`)
D. None of These

None of These
A. "String text = "Hello";
This is just a String assignment and has nothing to do with autounboxing. Strings are not primitive types or their wrappers.
B. "int value = Integer.parseInt("42");
This is a method call (Integer.parseInt) that converts a String to a primitive int. It does not involve converting a wrapper object to a primitive type, so it's not autounboxing.
C. "Double result = 3.14;
This is an example of autoboxing, where the primitive double value 3.14 is automatically converted to its wrapper class Double. Autoboxing is the opposite of autounboxing.