ExamVeda
Login
Home
This question belongs to Java Program Java Autoboxing
Java Autoboxing
?

In Java, which of the following is an example of autounboxing?

Answer & Solution
Correct Answer: Option D
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.
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Ganesh Commn
Ganesh Commn 1 year ago
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.