0
0
Kotlinprogramming~10 mins

Any type as universal base 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 that can hold any type of value.

Kotlin
val value: [1] = 42
Drag options to blanks, or click blank then click option'
AInt
BString
CAny
DUnit
Attempts:
3 left
💡 Hint
Common Mistakes
Using a specific type like Int or String limits the variable to that type only.
2fill in blank
medium

Complete the code to assign a string value to a variable of type Any.

Kotlin
val data: Any = [1]
Drag options to blanks, or click blank then click option'
Anull
B"Hello"
Ctrue
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a value without quotes when it should be a string.
3fill in blank
hard

Fix the error in the code by choosing the correct type for the variable that can hold any value.

Kotlin
var item: [1] = 3.14
Drag options to blanks, or click blank then click option'
AAny
BInt
CString
DDouble
Attempts:
3 left
💡 Hint
Common Mistakes
Using a specific type like Double limits the variable to only that type.
4fill in blank
hard

Fill both blanks to create a function that accepts any type and returns its string representation.

Kotlin
fun describe(value: [1]): [2] = value.toString()
Drag options to blanks, or click blank then click option'
AAny
BString
CInt
DUnit
Attempts:
3 left
💡 Hint
Common Mistakes
Using a specific type for the parameter or wrong return type.
5fill in blank
hard

Fill all three blanks to create a list of Any type and add different types of elements.

Kotlin
val items = mutableListOf<[1]>()
items.add([2])
items.add([3])
Drag options to blanks, or click blank then click option'
AAny
B"Kotlin"
C42
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Using a specific type for the list or adding elements without correct types.