Recall & Review
beginner
What does it mean that type conversion is always explicit in Kotlin?
It means you must manually convert one type to another using specific functions. Kotlin does not convert types automatically for you.
Click to reveal answer
beginner
How do you convert an Int to a Double in Kotlin?
You use the
toDouble() function, for example: val d = 5.toDouble().Click to reveal answer
intermediate
Why does Kotlin require explicit type conversion instead of automatic?
Explicit conversion helps avoid unexpected bugs by making conversions clear and intentional.
Click to reveal answer
beginner
Which function converts a String to an Int in Kotlin?
The function
toInt() converts a String to an Int, for example: "123".toInt().Click to reveal answer
beginner
What happens if you try to assign an Int value directly to a Double variable in Kotlin without conversion?
The code will not compile because Kotlin does not allow implicit type conversion between Int and Double.
Click to reveal answer
In Kotlin, how do you convert a Double to an Int?
✗ Incorrect
You must use the
toInt() function to explicitly convert a Double to an Int.What will happen if you write
val d: Double = 5 in Kotlin?✗ Incorrect
Kotlin requires explicit conversion, so you must write
val d: Double = 5.toDouble().Which of these is the correct way to convert a String "100" to Int in Kotlin?
✗ Incorrect
The correct Kotlin function is
toInt() called on the String.Why does Kotlin avoid implicit type conversion?
✗ Incorrect
Explicit conversions make the programmer aware of changes, reducing bugs.
Which function converts an Int to a Long in Kotlin?
✗ Incorrect
The function
toLong() converts an Int to a Long explicitly.Explain why Kotlin requires explicit type conversion and give an example converting Int to Double.
Think about how Kotlin treats type safety and how you convert types manually.
You got /4 concepts.
Describe what happens if you try to assign an Int value directly to a Double variable without conversion in Kotlin.
Remember Kotlin does not do automatic type changes.
You got /3 concepts.