Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q4 of 15
Java - Wrapper Classes
What is the output of the following code?
Integer i = Integer.valueOf("50");
int j = i.intValue();
System.out.println(j + 10);
A60
B5010
CCompilation error
DRuntime exception
Step-by-Step Solution
Solution:
  1. Step 1: Understand Integer.valueOf and intValue methods

    Integer.valueOf("50") returns Integer object with value 50. intValue() returns primitive int 50.
  2. Step 2: Calculate output of j + 10

    j is 50, adding 10 results in 60, printed as integer.
  3. Final Answer:

    60 -> Option A
  4. Quick Check:

    Integer to int conversion and addition = 60 [OK]
Quick Trick: intValue() extracts primitive int from Integer object [OK]
Common Mistakes:
  • Thinking j + 10 concatenates as string
  • Expecting compilation error due to boxing
  • Confusing Integer.valueOf with parseInt

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes