Comments in Kotlin
On this page (7sections)
Comments Definition and Overview
- The text preceded by // is the single line comments in Kotlin.
- The text line from /* to */ is the traditional comment or multi-line comments in Kotlin
- Comments are neglected by Kotlin compiler.
- Comments are designed for the better understanding of code and functionality and changes in the program.
In Kotlin, there are two types of comments in Kotlin similar to C, C++, and Java.
Types
- Single Line Comments
- Multi Line Comments
Syntax
// Single Line Comment
/*
Multi
Line
Comments
*/
Example Program
/* Comments Example Program
The program prints "Comments Example in kotlin" on the screen.
Multi-line Comments
*/
fun main(args: Array<String>) {
// prints Comments Example in kotlin - single line comments
println("Comments Example in kotlin")
}
Sample Output
Comments Example in kotlin
How It Works
This Kotlin program demonstrates Comments. It first prepares the data it needs, then performs the core operation step by step, and finally prints the output shown in the Sample Output above.
- Declare the variables that hold the program’s data.
- Print the final result to the console so you can compare it with the sample output.
Try changing the input values and re-running the program to see how the output changes — this is the fastest way to understand how the logic behaves.
Frequently Asked Questions
What is Comments in Kotlin?
Comments is demonstrated in this Kotlin tutorial with a complete, runnable example and its sample output.
How do I run this Kotlin example?
Run it in IntelliJ IDEA or Android Studio, or compile from the command line with `kotlinc file.kt -include-runtime -d file.jar` and run `java -jar file.jar`.
How can I practice Comments?
Copy the example into IntelliJ IDEA or Android Studio, run it, then change the values or add print statements to see how the output changes.