Bird
0
0

What will be the output of the following code?

medium📝 Predict Output Q13 of 15
Java - Wrapper Classes
What will be the output of the following code?
String s = "123";
Integer obj = Integer.valueOf(s);
int n = obj.intValue();
System.out.println(n + 10);
A133
BCompilation error
CNumberFormatException
D12310
Step-by-Step Solution
Solution:
  1. Step 1: Convert String to Integer object

    Integer.valueOf("123") creates Integer object with value 123.
  2. Step 2: Extract primitive int and add 10

    intValue() returns 123 as int. Adding 10 results in 133.
  3. Final Answer:

    133 -> Option A
  4. Quick Check:

    123 + 10 = 133 [OK]
Quick Trick: valueOf + intValue() converts string to int for math [OK]
Common Mistakes:
  • Thinking output is string concatenation
  • Expecting NumberFormatException for valid number string
  • Confusing intValue() usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes