Bird
0
0

What is the output of the following Java code?

medium📝 Predict Output Q4 of 15
Java - Command Line Arguments
What is the output of the following Java code?
String s = "256";
int num = Integer.parseInt(s);
System.out.println(num + 10);
A10
B266
CError at runtime
D25610
Step-by-Step Solution
Solution:
  1. Step 1: Parse string "256" to int

    Integer.parseInt("256") converts the string to integer 256.
  2. Step 2: Add 10 to parsed integer and print

    256 + 10 equals 266, so output is 266.
  3. Final Answer:

    266 -> Option B
  4. Quick Check:

    parseInt converts string to int, addition works normally [OK]
Quick Trick: parseInt converts string to int for arithmetic [OK]
Common Mistakes:
  • Expecting string concatenation instead of addition
  • Confusing parseInt with toString
  • Thinking runtime error occurs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes