Bird
Raised Fist0
Kotlinprogramming~20 mins

Comments and documentation syntax in Kotlin - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Kotlin Comments Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of code with single-line and multi-line comments
What is the output of this Kotlin code snippet?
Kotlin
fun main() {
    // This is a single-line comment
    val x = 5
    /* This is a
       multi-line comment */
    val y = 10
    println(x + y) // prints sum
}
A15
B510
CCompilation error due to comments
D5 + 10
Attempts:
2 left
💡 Hint
Remember that comments do not affect the code execution.
❓ Predict Output
intermediate
2:00remaining
Output of Kotlin code with KDoc documentation comments
What will be printed when running this Kotlin code?
Kotlin
/**
 * Returns the sum of two integers.
 * @param a first integer
 * @param b second integer
 * @return sum of a and b
 */
fun sum(a: Int, b: Int): Int {
    return a + b
}

fun main() {
    println(sum(3, 4))
}
ACompilation error due to KDoc
Bsum of a and b
C3 4
D7
Attempts:
2 left
💡 Hint
Documentation comments do not affect runtime output.
❓ Predict Output
advanced
2:00remaining
Effect of nested comments in Kotlin
What happens when you try to compile and run this Kotlin code?
Kotlin
fun main() {
    /* Start of comment
    /* Nested comment */
    End of comment */
    println("Hello")
}
ACompilation error due to nested comments
BPrints Hello
CPrints /* Nested comment */
DRuntime error
Attempts:
2 left
💡 Hint
Kotlin does not support nested block comments.
❓ Predict Output
advanced
2:00remaining
Output of code with commented out code lines
What is the output of this Kotlin program?
Kotlin
fun main() {
    val a = 10
    // val b = 20
    val c = 30
    // println(a + b)
    println(a + c)
}
ACompilation error due to b being undefined
B40
C30
D10
Attempts:
2 left
💡 Hint
Commented out code does not run or affect variables.
🧠 Conceptual
expert
3:00remaining
Identifying correct KDoc usage for function documentation
Which of the following KDoc comments correctly documents a Kotlin function that returns the maximum of two integers?
A
/*
 * Returns max of two integers
 * @param a first integer
 * @param b second integer
 * @return larger integer
 */
B
// Returns max of a and b
// a: first integer
// b: second integer
// returns larger integer
C
/**
 * Returns the maximum of two integers.
 * @param a first integer
 * @param b second integer
 * @return the larger integer
 */
D
/**
 * Returns max of two integers
 * @param a first integer
 * @param b second integer
 * @param c unused parameter
 * @return larger integer
 */
Attempts:
2 left
💡 Hint
KDoc uses /** ... */ with @param and @return tags.

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

  1. Step 1: Identify single-line comment syntax in Kotlin

    Kotlin uses // to start a single-line comment.
  2. 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.
  3. Final Answer:

    // This is a single-line comment -> Option C
  4. 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

  1. Step 1: Recall multi-line comment syntax in Kotlin

    Kotlin uses /* ... */ to write multi-line comments.
  2. 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.
  3. Final Answer:

    /* This is a multi-line comment */ -> Option A
  4. 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

  1. Step 1: Understand comment effect on code execution

    The line // println("Hello") is a comment, so it does not run.
  2. Step 2: Identify which println runs

    Only println("World") runs, so output is "World".
  3. Final Answer:

    World -> Option B
  4. 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

  1. Step 1: Check multi-line comment syntax

    The comment starts with /* but does not have a closing */.
  2. Step 2: Understand impact of missing closing comment

    Without closing */, the compiler treats the rest as comment, causing syntax error.
  3. Final Answer:

    Missing closing */ for multi-line comment -> Option D
  4. 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

  1. Step 1: Identify documentation comment syntax in Kotlin

    Kotlin uses /** ... */ for documentation comments that tools can parse.
  2. 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.
  3. Final Answer:

    /** This is a documentation comment */ -> Option A
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard