Challenge - 5 Problems
Kotlin Comments Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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 }
Attempts:
2 left
💡 Hint
Remember that comments do not affect the code execution.
✗ Incorrect
Comments are ignored by the compiler. The code adds x and y (5 + 10) and prints 15.
❓ Predict Output
intermediate2: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)) }
Attempts:
2 left
💡 Hint
Documentation comments do not affect runtime output.
✗ Incorrect
KDoc comments are for documentation only and do not affect the program output. The sum function returns 7.
❓ Predict Output
advanced2: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") }
Attempts:
2 left
💡 Hint
Kotlin does not support nested block comments.
✗ Incorrect
Kotlin block comments cannot be nested. The compiler will raise an error.
❓ Predict Output
advanced2: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) }
Attempts:
2 left
💡 Hint
Commented out code does not run or affect variables.
✗ Incorrect
The variable b and the print statement using b are commented out, so only a + c (10 + 30) is printed.
🧠 Conceptual
expert3: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?
Attempts:
2 left
💡 Hint
KDoc uses /** ... */ with @param and @return tags.
✗ Incorrect
Option C uses proper KDoc syntax with correct tags. Option C uses single-line comments, not KDoc. Option C uses block comments but not KDoc style. Option C has an incorrect @param tag for a non-existent parameter.