0
0
Kotlinprogramming~20 mins

Explicit type declaration in Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kotlin Explicit Type Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Kotlin code with explicit type declaration?
Consider the following Kotlin code snippet. What will it print when run?
Kotlin
val number: Int = 10
val text: String = "Hello"
println("$text $number")
ACompilation error
BHello 10
C10 Hello
DHello10
Attempts:
2 left
💡 Hint
Look at how the variables are combined inside the println statement.
Predict Output
intermediate
2:00remaining
What is the type of variable 'result' after this declaration?
Given the Kotlin code below, what is the explicit type of 'result'?
Kotlin
val result: Double = 5 / 2
ADouble with value 2.5
BCompilation error
CInt with value 2
DDouble with value 2.0
Attempts:
2 left
💡 Hint
Remember that 5 and 2 are integers and division between integers behaves differently.
🔧 Debug
advanced
2:00remaining
Which option causes a compilation error due to explicit type mismatch?
Identify which Kotlin code snippet will cause a compilation error because the assigned value does not match the explicitly declared type.
Aval price: Double = 19.99
Bval age: Int = 30
Cval name: String = 123
Dval isActive: Boolean = true
Attempts:
2 left
💡 Hint
Check if the value assigned matches the declared type exactly.
Predict Output
advanced
2:00remaining
What is the output of this Kotlin code with explicit nullable type?
Analyze the Kotlin code below and select the correct output.
Kotlin
val message: String? = null
println(message ?: "No message")
ANo message
Bnull
CCompilation error
DEmpty string
Attempts:
2 left
💡 Hint
The Elvis operator ?: returns the right side if the left side is null.
🧠 Conceptual
expert
2:00remaining
How many variables are explicitly declared as nullable in this Kotlin code?
Count the number of variables explicitly declared with nullable types in the following Kotlin code snippet.
Kotlin
val a: Int? = null
val b: String = "text"
val c: Double? = 3.14
val d: Boolean = true
val e: List<String>? = null
A3
B1
C4
D2
Attempts:
2 left
💡 Hint
Look for the question mark '?' after the type name.