Every Kotlin program needs an entry point—top-level fun main(). Output uses println, similar to System.out.println in Java or print() in Python without requiring a class wrapper.
Minimal program
fun main() {
println("Hello, World")
}
println writes a line to stdout. Semicolons are optional; expressions often omit them.
Compared to Java
Java requires public class Main matching the filename. Kotlin allows multiple functions in one file—the compiler generates a MainKt class for top-level main.
Important interview questions and answers
- Q: What prints text in Kotlin?
A:println,print, andprintf-style formatting with string templates. - Q: Must every Kotlin file declare a class?
A: No—top-level functions and properties are idiomatic.
Self-check
- Which function is the program entry point?
- What JVM class runs when you compile
main.kt?
Tip: Top-level fun main() needs no class wrapper—unlike Java public class Main.
Interview prep
- What prints text?
println, print, and string templates.
- Entry point?
Top-level fun main().