0
0
Kotlinprogramming~20 mins

Main function as entry point in Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kotlin Main Function Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1: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!")
}
ANo output
Bhello, kotlin!
CHello, Kotlin!
DCompilation error
Attempts:
2 left
💡 Hint
The main function is the starting point of a Kotlin program.
Predict Output
intermediate
1: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}")
}
ACompilation error
BArguments count: 0
CRuntime error
DArguments count: null
Attempts:
2 left
💡 Hint
The args array is always passed, even if empty.
Predict Output
advanced
2: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")
}
AFirst main
BNo output
CCompilation error due to duplicate main
DSecond main
Attempts:
2 left
💡 Hint
Kotlin prefers main with parameters as entry point.
Predict Output
advanced
1: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)
}
ARuntime error: main function must have Array<String> parameter or no parameters
BRuntime error: wrong argument type
CPrints the string argument
DNo output
Attempts:
2 left
💡 Hint
Main function signature must be exact.
🧠 Conceptual
expert
2: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.
ATwo main functions are allowed: one with no parameters and one with Array<String> parameter
BOnly one main function is allowed, with Array<String> parameter
COnly one main function is allowed, with no parameters
DMultiple main functions with any signatures are allowed
Attempts:
2 left
💡 Hint
Kotlin supports main function overloading with specific signatures.