Vidyalelo
Java Programming · Q22

Java Autoboxing

Programming · Java Programming · question 22

Q22

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

Answer: Option D

Solution

Answer: Option D
Solution:
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.