Examveda

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.

This Question Belongs to Java Program >> Java Autoboxing

Join The Discussion

Comments (1)

  1. Ganesh Commn
    Ganesh Commn:
    3 months 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.

Related Questions on Java Autoboxing

What is autoboxing in Java?

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