Concept Flow - Main function as entry point
Program starts
Look for main()
Execute main() code
Program ends
The program starts by looking for the main() function and runs its code as the entry point, then ends.
fun main() { println("Hello, Kotlin!") }
| Step | Action | Code Executed | Output |
|---|---|---|---|
| 1 | Program starts and looks for main() | fun main() {...} | |
| 2 | main() function is called | main() | |
| 3 | Print statement runs | println("Hello, Kotlin!") | Hello, Kotlin! |
| 4 | main() finishes execution | } | |
| 5 | Program ends |
| Variable | Start | After main() starts | After println | Final |
|---|---|---|---|---|
| No variables | - | - | - | - |
fun main() {
// code here
}
- main() is the program's entry point
- Program starts by running main()
- Code outside main() does not run automatically
- println() outputs text to consolemain function in a Kotlin program?main in Kotlinmain function is where Kotlin programs begin execution.main is the program's starting point.fun, followed by the name and parentheses.fun main() correctly; others use wrong keywords or miss fun.fun main() {
println("Start")
println("End")
}println adds a new line after each output, so outputs appear on separate lines.fun main(args: String) {
println("Hello")
}Array<String> or Array<String>, not a single String.println is valid; return type is optional for Unit.Array<String> to receive command-line arguments.args correctly and prints each argument.Pass the test and this pattern moves unknown