Bird
0
0

Why does Kotlin's main function usually have a return type of Unit instead of Int like in some other languages?

hard📝 Conceptual Q10 of 15
Kotlin - Basics and JVM Runtime
Why does Kotlin's main function usually have a return type of Unit instead of Int like in some other languages?
ABecause Kotlin uses exceptions to signal program termination.
BBecause Kotlin does not support returning values from functions.
CBecause Kotlin programs do not return exit codes by default.
DBecause main functions must always be void in all languages.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Kotlin main function return type

    Kotlin's main returns Unit, meaning no value, unlike C/C++ where main returns Int exit code.
  2. Step 2: Reason why Kotlin uses Unit

    Kotlin programs do not return exit codes by default; the OS assumes success unless exceptions occur.
  3. Final Answer:

    Because Kotlin programs do not return exit codes by default. -> Option C
  4. Quick Check:

    Main return type Unit means no exit code [OK]
Quick Trick: Kotlin main returns Unit; exit codes not returned by default [OK]
Common Mistakes:
MISTAKES
  • Thinking Kotlin disallows return values
  • Assuming all languages require void main
  • Believing exceptions replace all returns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes