Bird
0
0

Consider this Kotlin code:

hard📝 Application Q9 of 15
Kotlin - Data Types
Consider this Kotlin code:
fun process(): Unit {
    println("Start")
    return Unit
}

fun main() {
    val result = process()
    println(result)
}

What will be printed?
AStart\nnull
BStart\nkotlin.Unit
CStart\nUnit()
DStart\nvoid
Step-by-Step Solution
Solution:
  1. Step 1: Analyze process function and understand printing result

    The function prints "Start" and returns the singleton Unit explicitly. Printing result prints kotlin.Unit string representation.
  2. Final Answer:

    Start\nkotlin.Unit -> Option B
  3. Quick Check:

    Unit prints as kotlin.Unit [OK]
Quick Trick: Unit prints as kotlin.Unit when printed [OK]
Common Mistakes:
MISTAKES
  • Expecting null instead of kotlin.Unit
  • Thinking Unit prints as Unit()
  • Assuming void is printed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes