Bird
0
0

What is the output of this code?

medium📝 Predict Output Q4 of 15
Java - Methods and Code Reusability
What is the output of this code?
public class Test {
  public static int getNumber() {
    return 5;
  }
  public static void main(String[] args) {
    System.out.println(getNumber());
  }
}
Anull
B0
C5
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the getNumber method

    The method returns the integer 5.
  2. Step 2: Check main method output

    The main method prints the value returned by getNumber, which is 5.
  3. Final Answer:

    5 -> Option C
  4. Quick Check:

    Return value printed = 5 [OK]
Quick Trick: Returned value is printed exactly [OK]
Common Mistakes:
  • Expecting 0 as default
  • Confusing return with print
  • Thinking null is printed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes