0
0
Kotlinprogramming~10 mins

Object declaration syntax 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 singleton object named Logger.

Kotlin
object [1] {
    fun log(message: String) {
        println(message)
    }
}
Drag options to blanks, or click blank then click option'
Alogger
BLog
CLogger
DLogObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names for the object.
Forgetting to use the object keyword.
2fill in blank
medium

Complete the code to call the log function of the Logger object.

Kotlin
fun main() {
    [1].log("Hello, Kotlin!")
}
Drag options to blanks, or click blank then click option'
ALogger
BLogObject
Clogger
DLog
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or incorrect object names.
Trying to create an instance instead of using the object directly.
3fill in blank
hard

Fix the error in the object declaration syntax.

Kotlin
object [1] {
    fun greet() = println("Hi!")
}
Drag options to blanks, or click blank then click option'
Agreeter
BGreeter
CGreeterObject
DGreeter()
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses after the object name.
Using lowercase names for objects.
4fill in blank
hard

Fill both blanks to declare an object with a property and a function.

Kotlin
object [1] {
    val [2] = "Kotlin"
    fun printName() = println(name)
}
Drag options to blanks, or click blank then click option'
AAppConfig
BappName
Cname
DConfig
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatch between property name and usage in function.
Using lowercase object names.
5fill in blank
hard

Fill all three blanks to create an object with a mutable property and a function to update it.

Kotlin
object [1] {
    var [2] = 0
    fun [3](value: Int) {
        count = value
    }
}
Drag options to blanks, or click blank then click option'
ACounter
Bcount
CupdateCount
Dcounter
Attempts:
3 left
💡 Hint
Common Mistakes
Using immutable property val instead of var.
Mismatch between property and function parameter names.