Bird
0
0

Given this Java code:

hard📝 Application Q15 of 15
Java - Methods and Code Reusability
Given this Java code:
public class Calculator {
  public static int add(int a, int b) {
    return a + b;
  }
  public static void main(String[] args) {
    int result = add(5, 3);
    System.out.println(result);
  }
}

What will be printed when the program runs?
A8
B53
Cadd(5, 3)
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Understand method add parameters and return

    The method add takes two integers and returns their sum.
  2. Step 2: Analyze the call add(5, 3)

    It returns 5 + 3 = 8, which is stored in result.
  3. Step 3: Check the output statement

    System.out.println(result); prints the value 8.
  4. Final Answer:

    8 -> Option A
  5. Quick Check:

    Sum of 5 and 3 = 8 [OK]
Quick Trick: Method returns sum; print shows result [OK]
Common Mistakes:
  • Concatenating numbers as strings instead of adding
  • Expecting method name printed instead of result
  • Confusing return value with method call syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes