0
0
Kotlinprogramming~10 mins

Lazy property delegation 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 lazy property named value initialized with 10.

Kotlin
val value by [1] { 10 }
Drag options to blanks, or click blank then click option'
AlazyInit
Blazy
Cdelegate
DlazyValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that does not exist like 'delegate' or 'lazyValue'.
Forgetting to use the 'by' keyword before the lazy function.
2fill in blank
medium

Complete the code to print the lazy property value.

Kotlin
println([1])
Drag options to blanks, or click blank then click option'
Avalue
Blazy.value
Cvalue()
Dlazy()
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call the property as a function with parentheses.
Using the delegate name instead of the property name.
3fill in blank
hard

Fix the error in the lazy property declaration by completing the code.

Kotlin
val number by [1] 42
Drag options to blanks, or click blank then click option'
Alazy {
Blazy {}
Clazy()
Dlazy
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the value directly without curly braces.
Using parentheses without a lambda block.
4fill in blank
hard

Fill both blanks to create a lazy property text initialized with "Hello" and print it.

Kotlin
val text by [1] { "Hello" }
println([2])
Drag options to blanks, or click blank then click option'
Alazy
Btext()
Ctext
DlazyValue
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call the property as a function.
Using an incorrect delegate name.
5fill in blank
hard

Fill all three blanks to create a lazy property count initialized with 5, print it, and then print count multiplied by 2.

Kotlin
val count by [1] { 5 }
println([2])
println([3] * 2)
Drag options to blanks, or click blank then click option'
Alazy
Bcount
DlazyValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using an incorrect delegate name.
Calling the property as a function.