Bird
0
0

What will be the output of the following Java program?

medium📝 Predict Output Q4 of 15
Java - Methods and Code Reusability
What will be the output of the following Java program?
public class Example {
  public static void main(String[] args) {
    alpha();
  }
  static void alpha() {
    beta();
    System.out.println("Alpha finished");
  }
  static void beta() {
    System.out.println("Beta finished");
  }
}
ABeta finished Alpha finished
BAlpha finished Beta finished
CAlpha finished
DBeta finished
Step-by-Step Solution
Solution:
  1. Step 1: Trace method calls

    Main calls alpha(), which calls beta() first.
  2. Step 2: Output order

    beta() prints "Beta finished" then returns control to alpha(), which prints "Alpha finished".
  3. Final Answer:

    Beta finished Alpha finished -> Option A
  4. Quick Check:

    Method calls print in call order [OK]
Quick Trick: Inner method prints before outer method resumes [OK]
Common Mistakes:
  • Assuming outer method prints before inner method
  • Ignoring method call order
  • Confusing return order with print order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes