Challenge - 5 Problems
Kotlin Main Function Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:00remaining
What is the output of this Kotlin program?
Consider this Kotlin program with a main function. What will it print when run?
Kotlin
fun main() { println("Hello, Kotlin!") }
Attempts:
2 left
💡 Hint
The main function is the starting point of a Kotlin program.
✗ Incorrect
The main function runs first and prints the exact string inside println, preserving case.
❓ Predict Output
intermediate1:30remaining
What happens if main has parameters but is called without arguments?
Look at this Kotlin main function with parameters. What will happen if you run this program without passing any command-line arguments?
Kotlin
fun main(args: Array<String>) { println("Arguments count: ${args.size}") }
Attempts:
2 left
💡 Hint
The args array is always passed, even if empty.
✗ Incorrect
The args array is empty if no command-line arguments are given, so size is 0.
❓ Predict Output
advanced2:00remaining
What is the output of this Kotlin program with multiple main functions?
This Kotlin file has two main functions. Which one will run and what will be printed?
Kotlin
fun main() { println("First main") } fun main(args: Array<String>) { println("Second main") }
Attempts:
2 left
💡 Hint
Kotlin prefers main with parameters as entry point.
✗ Incorrect
When running from command line, Kotlin uses main with Array parameter if present.
❓ Predict Output
advanced1:30remaining
What error does this Kotlin program produce?
This Kotlin program tries to define main with a wrong signature. What error will it cause?
Kotlin
fun main(args: String) { println(args) }
Attempts:
2 left
💡 Hint
Main function signature must be exact.
✗ Incorrect
Kotlin requires main to have either no parameters or Array parameter; String alone is invalid.
🧠 Conceptual
expert2:00remaining
How many main functions can a Kotlin program have without causing errors?
Select the correct statement about the number of main functions allowed in a Kotlin program.
Attempts:
2 left
💡 Hint
Kotlin supports main function overloading with specific signatures.
✗ Incorrect
Kotlin allows exactly two main functions: one with no parameters and one with Array parameter, to support different entry points.