Recall & Review
beginner
What is an object declaration in Kotlin?
An object declaration in Kotlin creates a singleton object, which means only one instance of that object exists throughout the program.
Click to reveal answer
beginner
How do you declare a simple object named
Logger in Kotlin?Use the syntax:
object Logger {
fun log(message: String) {
println(message)
}
}Click to reveal answer
intermediate
Can an object declaration have properties and functions in Kotlin?
Yes, an object declaration can have properties and functions just like a class, but it cannot have constructors because it is a singleton.
Click to reveal answer
intermediate
What is the difference between an object declaration and a class in Kotlin?An object declaration creates a single instance automatically (singleton), while a class can have many instances created using constructors.Click to reveal answer
beginner
How do you access a function inside an object declaration?
You access it directly by the object name, for example:
Logger.log("Hello") without creating an instance.Click to reveal answer
What keyword is used to declare a singleton object in Kotlin?
✗ Incorrect
The keyword
object is used to declare a singleton object in Kotlin.Can an object declaration in Kotlin have a constructor?
✗ Incorrect
Object declarations cannot have constructors because they are instantiated automatically as singletons.
How do you call a function named
printMessage inside an object named Notifier?✗ Incorrect
You call the function directly on the object name:
Notifier.printMessage().Which of the following is true about Kotlin object declarations?
✗ Incorrect
Object declarations are instantiated lazily and only once, making them singletons.
What happens if you try to create an instance of an object declaration using a constructor?
✗ Incorrect
Since object declarations have no constructors, trying to instantiate them causes a compile-time error.
Explain how to declare and use an object declaration in Kotlin.
Think about how you create a single shared tool or helper in your program.
You got /4 concepts.
Describe the differences between a Kotlin object declaration and a class.
Consider how many copies you want in your program.
You got /4 concepts.