0
0
Kotlinprogramming~10 mins

Type inference by the compiler in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a variable with type inferred by the compiler.

Kotlin
val number = [1]
Drag options to blanks, or click blank then click option'
Atrue
B"Hello"
C3.14
D42
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string or boolean value when an integer is expected.
2fill in blank
medium

Complete the code to declare a variable with type inferred as String.

Kotlin
val greeting = [1]
Drag options to blanks, or click blank then click option'
A"Welcome"
B100
Cfalse
D2.718
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a number or boolean instead of a string.
3fill in blank
hard

Fix the error by completing the code to declare a variable with type inferred as Boolean.

Kotlin
val isActive = [1]
Drag options to blanks, or click blank then click option'
Atrue
B"true"
C1
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string "true" instead of boolean true.
Using numbers or null instead of boolean.
4fill in blank
hard

Fill both blanks to create a list with type inferred by the compiler.

Kotlin
val numbers = listOf([1], [2])
Drag options to blanks, or click blank then click option'
A1
B"two"
C3
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing types like string and integer in the list elements.
5fill in blank
hard

Fill all three blanks to create a map with type inferred by the compiler.

Kotlin
val map = mapOf([1] to [2], [3] to 42)
Drag options to blanks, or click blank then click option'
A"one"
B1
C"two"
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using integers as keys and strings as values inconsistently.