Bird
0
0

Which of the following is the correct syntax for a Kotlin main function without parameters?

easy📝 Syntax Q3 of 15
Kotlin - Basics and JVM Runtime
Which of the following is the correct syntax for a Kotlin main function without parameters?
Amain fun() { println("Hello") }
Bfun main() { println("Hello") }
Cfun main(String[] args) { println("Hello") }
Dfun main(args: String) { println("Hello") }
Step-by-Step Solution
Solution:
  1. Step 1: Recall Kotlin main function syntax

    The correct syntax for main without parameters is fun main() { ... }.
  2. Step 2: Check each option's syntax

    The option 'main fun() { println("Hello") }' has incorrect keyword order. 'fun main(args: String) { println("Hello") }' uses wrong parameter type. 'fun main(String[] args) { println("Hello") }' uses invalid Java-style syntax. Only 'fun main() { println("Hello") }' matches correct Kotlin syntax.
  3. Final Answer:

    fun main() { println("Hello") } -> Option B
  4. Quick Check:

    Main syntax no params = fun main() [OK]
Quick Trick: Main function syntax: fun main() { } [OK]
Common Mistakes:
MISTAKES
  • Using Java-style parameter syntax
  • Placing keywords in wrong order
  • Adding incorrect parameter types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes