Bird
0
0

Identify the problem in this Java code snippet:

medium📝 Debug Q7 of 15
Java - Methods and Code Reusability
Identify the problem in this Java code snippet:
static int multiply(int x, int y) {
  System.out.println(x * y);
}
AMethod cannot print inside its body
BMethod should return an int but has no return statement
CParameters must be declared outside parentheses
DMethod name multiply is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check method return type and body

    The method declares it returns int but only prints result without returning.
  2. Step 2: Identify missing return statement

    It must return the product value to match return type.
  3. Final Answer:

    Method should return an int but has no return statement -> Option B
  4. Quick Check:

    Return type requires return statement [OK]
Quick Trick: Return type must match returned value or statement [OK]
Common Mistakes:
  • Printing instead of returning value
  • Misplacing parameter declarations
  • Assuming method names are restricted

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes