Bird
0
0

What will be the output of the following Java code?

medium📝 Predict Output Q13 of 15
Java - Custom Exceptions
What will be the output of the following Java code?
public class Test {
    public static void main(String[] args) {
        int x = 5;
        int y = 10;
        int sum = x + y;
        System.out.println("Sum is: " + sum);
    }
}
ASum is: 510
BSum is: 15
CSum is: x + y
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable values and addition

    Variables x and y hold 5 and 10, sum is their addition: 5 + 10 = 15.
  2. Step 2: Check output statement

    Prints "Sum is: " concatenated with sum value 15.
  3. Final Answer:

    Sum is: 15 -> Option B
  4. Quick Check:

    5 + 10 = 15 output = Sum is: 15 [OK]
Quick Trick: Add numbers before printing to avoid string concatenation errors [OK]
Common Mistakes:
  • Concatenating numbers as strings without addition
  • Confusing variable names with strings
  • Syntax errors from missing semicolons

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes