Bird
0
0

Which of the following is the correct syntax for the main function in Kotlin?

easy📝 Syntax Q12 of 15
Kotlin - Basics and JVM Runtime
Which of the following is the correct syntax for the main function in Kotlin?
Adef main() { println("Hello") }
Bfunction main() { println("Hello") }
Cfun main() { println("Hello") }
Dmain() { println("Hello") }
Step-by-Step Solution
Solution:
  1. Step 1: Recall Kotlin function syntax

    Kotlin functions start with fun, followed by the name and parentheses.
  2. Step 2: Check each option

    Only fun main() { println("Hello") } uses fun main() correctly; others use wrong keywords or miss fun.
  3. Final Answer:

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

    fun keyword + main() = correct syntax [OK]
Quick Trick: Kotlin functions start with 'fun' keyword [OK]
Common Mistakes:
MISTAKES
  • Using 'function' instead of 'fun'
  • Using 'def' like Python
  • Omitting 'fun' keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes