Bird
0
0

What will be the output of this Java code?

medium📝 Predict Output Q13 of 15
Java - Methods and Code Reusability
What will be the output of this Java code?
public class Test {
  public static void printSum(int x, int y) {
    System.out.println(x + y);
  }
  public static void main(String[] args) {
    printSum(5, 3);
  }
}
A8
B53
Cx + y
DCompile error
Step-by-Step Solution
Solution:
  1. Step 1: Understand method call with parameters

    The method printSum is called with 5 and 3 as arguments, assigned to x and y.
  2. Step 2: Calculate the sum inside the method

    Inside printSum, it prints x + y which is 5 + 3 = 8.
  3. Final Answer:

    8 -> Option A
  4. Quick Check:

    5 + 3 = 8 [OK]
Quick Trick: Sum parameters values to get output [OK]
Common Mistakes:
  • Concatenating numbers as strings
  • Expecting variable names printed
  • Thinking code won't compile

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes