main function in Kotlin

main function in Kotlin is the entry point to a Kotlin program.

Kotlin supports both procedural programming and object oriented programming. If you have worked with some of the procedural languages, you may know that main() is the entry point to a program. Similarly, for Kotlin language as well, main() function (or method) in Kotlin file is the entry point to a Kotlin program. And you can write a class along with the main function in your Kotlin file.

In this section, we shall see a pictorial representation of the Kotlin file with main function, a data class and some helper functions.

main function in Kotlin - Kotlin Tutorial -

An example Kotlin file, KotlinMainFunctionExample.kt is given below to demonstrate the main() function in Kotlin Program.

Output :


Conclusion :

In this Kotlin Tutorial, we have learnt that main() function is an entry point to Kotlin program like in most of the procedural programming languages.