Recall & Review
beginner
What is the purpose of the
main function in a Kotlin program?The
main function is the starting point of a Kotlin program. When you run the program, the code inside main is executed first.Click to reveal answer
beginner
How do you declare the
main function in Kotlin that takes no arguments?You declare it like this:
fun main() {
// code here
} This function runs when the program starts.Click to reveal answer
intermediate
Can the
main function in Kotlin accept command-line arguments? If yes, how?Yes, it can accept arguments as an array of strings:
fun main(args: Array<String>) {
// use args here
} This lets you use inputs from the command line.Click to reveal answer
beginner
What happens if you write a Kotlin program without a
main function?The program will not run because Kotlin needs a
main function as the entry point to start executing code.Click to reveal answer
intermediate
Is it possible to have multiple
main functions in a Kotlin project?Yes, but only one
main function is used when you run the program. You can have multiple in different files for testing or different programs, but you must specify which one to run.Click to reveal answer
What is the correct way to declare a
main function in Kotlin that accepts command-line arguments?✗ Incorrect
The correct syntax is
fun main(args: Array) {} to accept command-line arguments.What role does the
main function play in a Kotlin program?✗ Incorrect
The
main function is the entry point where the program begins execution.Which of these is NOT a valid
main function declaration in Kotlin?✗ Incorrect
The
main function must accept Array<String>, not List<String>.What happens if you run a Kotlin program without a
main function?✗ Incorrect
Kotlin requires a
main function as the entry point; without it, the program cannot run.Can you have multiple
main functions in a Kotlin project?✗ Incorrect
You can have multiple
main functions in different files, but only one is used when you run the program.Explain the role of the
main function in Kotlin and how to declare it.Think about where the program begins and how you write the function.
You got /4 concepts.
Describe what happens if a Kotlin program does not have a
main function.Consider what Kotlin needs to start running code.
You got /3 concepts.