Overriding member function

Report a typo

Consider the following code:

class Cat(var sleeping: Boolean) {
    fun wakeUp() {
        sleeping = false
    }
}

fun Cat.wakeUp() {
    this.sleeping = true
}

fun main() {
    val cat = Cat(false)
    cat.wakeUp()
    println(cat.sleeping)
}

The code ...

Select one option from the list
___

Create a free account to access the full topic