What is the syntax for a single-line comment in Kotlin?
Use two forward slashes // before the comment text. Everything after // on that line is ignored by the compiler.
Click to reveal answer
beginner
How do you write a multi-line comment in Kotlin?
Start with /* and end with */. Everything between these markers is treated as a comment, even if it spans multiple lines.
Click to reveal answer
intermediate
What is the purpose of KDoc in Kotlin?
KDoc is Kotlin's documentation syntax. It helps you write clear explanations for classes, functions, and properties that tools can use to generate documentation.
Click to reveal answer
intermediate
How do you write a KDoc comment for a function in Kotlin?
Use /** ... */ before the function. Inside, you can add descriptions and tags like @param and @return to explain parameters and return values.
Click to reveal answer
advanced
Can you nest multi-line comments in Kotlin?
Yes, Kotlin allows nesting multi-line comments. You can start a new /* ... */ comment inside another multi-line comment.
Click to reveal answer
Which symbol starts a single-line comment in Kotlin?
A/*
B<!--
C#
D//
✗ Incorrect
Single-line comments in Kotlin start with two forward slashes //.
How do you write a multi-line comment in Kotlin?
A/* comment */
B# comment
C<!-- comment -->
D// comment
✗ Incorrect
Multi-line comments in Kotlin start with /* and end with */.
What is the correct way to start a KDoc comment?
A/**
B/*
C//
D<!--
✗ Incorrect
KDoc comments start with /** and end with */.
Which tag is used in KDoc to describe a function parameter?
A@throws
B@return
C@param
D@author
✗ Incorrect
The @param tag describes a function parameter in KDoc.
Can multi-line comments be nested in Kotlin?
ANo
BYes
COnly in single-line comments
DOnly in KDoc comments
✗ Incorrect
Kotlin supports nesting multi-line comments inside other multi-line comments.
Explain the different types of comments available in Kotlin and when to use each.
Think about quick notes, longer explanations, and documentation.
You got /4 concepts.
Describe how to write a KDoc comment for a function including parameters and return value.
Imagine explaining your function to a friend who will use it.
You got /4 concepts.
Practice
(1/5)
1. Which of the following is the correct way to write a single-line comment in Kotlin?
easy
A. /* This is a single-line comment */
B.
C. // This is a single-line comment
D. # This is a single-line comment
Solution
Step 1: Identify single-line comment syntax in Kotlin
Kotlin uses // to start a single-line comment.
Step 2: Compare options
// This is a single-line comment uses //, which is correct. /* This is a single-line comment */ is for multi-line comments. <!-- This is a single-line comment --> is HTML style. # This is a single-line comment is used in some scripting languages but not Kotlin.
Final Answer:
// This is a single-line comment -> Option C
Quick Check:
Single-line comment = // [OK]
Hint: Single-line comments start with // in Kotlin [OK]
Common Mistakes:
Using /* */ for single-line comments
Using # or which are not Kotlin comments
Confusing multi-line and single-line comment syntax
2. Which of the following is the correct syntax for a multi-line comment in Kotlin?
easy
A. /* This is a multi-line comment */
B.
C. /** This is a multi-line comment */
D. // This is a multi-line comment
Solution
Step 1: Recall multi-line comment syntax in Kotlin
Kotlin uses /* ... */ to write multi-line comments.
Step 2: Analyze options
/* This is a multi-line comment */ correctly uses /* ... */. // This is a multi-line comment is single-line comment syntax. /** This is a multi-line comment */ is documentation comment syntax. <!-- This is a multi-line comment --> is HTML comment syntax.
Final Answer:
/* This is a multi-line comment */ -> Option A
Quick Check:
Multi-line comment = /* ... */ [OK]
Hint: Multi-line comments use /* and */ to start and end [OK]
Common Mistakes:
Using // for multi-line comments
Confusing documentation comments /** */ with regular multi-line comments
Using HTML style comments
3. What will be the output of the following Kotlin code?
fun main() {
// println("Hello")
println("World")
}
medium
A. Hello
World
B. World
C. Hello
D. No output
Solution
Step 1: Understand comment effect on code execution
The line // println("Hello") is a comment, so it does not run.
Step 2: Identify which println runs
Only println("World") runs, so output is "World".
Final Answer:
World -> Option B
Quick Check:
Commented code does not run = World [OK]
Hint: Commented lines do not execute, only uncommented print runs [OK]
Common Mistakes:
Thinking commented println runs
Expecting both lines to print
Confusing comment syntax and output
4. Identify the error in the following Kotlin code snippet:
fun main() {
/* This is a comment
println("Hello")
}
medium
A. No error, code runs fine
B. Incorrect single-line comment syntax
C. Missing quotation marks in println
D. Missing closing */ for multi-line comment
Solution
Step 1: Check multi-line comment syntax
The comment starts with /* but does not have a closing */.
Step 2: Understand impact of missing closing comment
Without closing */, the compiler treats the rest as comment, causing syntax error.
Final Answer:
Missing closing */ for multi-line comment -> Option D
Quick Check:
Multi-line comments must close with */ [OK]
Hint: Always close multi-line comments with */ [OK]
Common Mistakes:
Forgetting to close multi-line comments
Confusing single-line and multi-line comment syntax
Assuming code inside unclosed comment runs
5. Which comment style should you use in Kotlin to write documentation that tools can extract to generate API docs?
hard
A. /** This is a documentation comment */
B. /* This is a documentation comment */
C. // This is a documentation comment
D.
Solution
Step 1: Identify documentation comment syntax in Kotlin
Kotlin uses /** ... */ for documentation comments that tools can parse.
Step 2: Compare with other comment types
// This is a documentation comment is single-line comment syntax. /* This is a documentation comment */ is regular multi-line comment syntax. <!-- This is a documentation comment --> is HTML comment syntax.
Final Answer:
/** This is a documentation comment */ -> Option A
Quick Check:
Documentation comments use /** ... */ [OK]
Hint: Use /** ... */ for documentation comments in Kotlin [OK]
Common Mistakes:
Using // or /* */ for documentation comments
Confusing documentation comments with regular comments
Using HTML comment style by mistake
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.