Bird
0
0

What will be printed when the following Swift program runs?

medium📝 Predict Output Q4 of 15
Swift - Basics and Runtime
What will be printed when the following Swift program runs?
@main enum Demo {
    static func main() {
        print("Begin")
        print("Finish")
    }
}
ABegin\nFinish
BFinish\nBegin
CBegin
DNo output due to error
Step-by-Step Solution
Solution:
  1. Step 1: Understand program flow

    The main() method prints "Begin" then "Finish" sequentially.
  2. Step 2: Confirm no errors

    Using @main on an enum with a static main() method is valid.
  3. Final Answer:

    Begin\nFinish -> Option A
  4. Quick Check:

    Static main() runs in order, prints both lines [OK]
Quick Trick: Static main() executes sequentially, prints all lines [OK]
Common Mistakes:
  • Assuming enum cannot be @main
  • Expecting reversed print order
  • Thinking program will fail to compile

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes