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 console