Bird
0
0

Why does Swift require the main() method marked by @main to be static?

hard📝 Conceptual Q10 of 15
Swift - Basics and Runtime
Why does Swift require the main() method marked by @main to be static?
ABecause static methods are faster to execute.
BBecause the program starts without creating an instance of the type.
CBecause instance methods cannot print output.
DBecause static methods run on the main thread only.
Step-by-Step Solution
Solution:
  1. Step 1: Understand program startup

    When a Swift program starts, it does not create an instance of the @main type automatically.
  2. Step 2: Reason why main() must be static

    Static methods can be called without an instance, so main() must be static to be called at startup.
  3. Final Answer:

    Because the program starts without creating an instance of the type. -> Option B
  4. Quick Check:

    Static main() runs without needing an instance [OK]
Quick Trick: Static main() runs without needing an instance [OK]
Common Mistakes:
  • Thinking static means main thread only
  • Assuming instance methods can be entry points
  • Believing static methods are faster

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes