Bird
0
0

Identify the error in this Swift program using @main:

medium📝 Debug Q14 of 15
Swift - Basics and Runtime
Identify the error in this Swift program using @main:
@main class App {
    func main() {
        print("Hello")
    }
}
AThe @main attribute cannot be used on a class.
BThe main() method must be static.
CThe print statement is invalid inside main().
DThe class must be a struct instead.
Step-by-Step Solution
Solution:
  1. Step 1: Check the main() method signature

    The @main type must have a static main() method to serve as the entry point.
  2. Step 2: Identify the missing static keyword

    Here, main() is an instance method, missing static, causing a compile error.
  3. Final Answer:

    The main() method must be static. -> Option B
  4. Quick Check:

    main() must be static in @main type [OK]
Quick Trick: Static main() is required inside @main type [OK]
Common Mistakes:
  • Omitting static keyword on main()
  • Thinking @main can't be on classes
  • Confusing instance and static methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes