Inferred type

Report a typo

We have the following code:

abstract class Animal() {
    abstract fun makeSound(): String
}

class Cat: Animal() {
    override fun makeSound() = "Meow!"
}

class Dog: Animal() {
    override fun makeSound() = "Woof!"
}

fun main() {
    val cat = Cat()
    val dog = Dog()
    val animals = mutableListOf(cat, dog)
    for (animal in animals) {
        println(animal.makeSound())
    }
}

What is the inferred type of the variable animals?

Enter a short text

Create a free account to access the full topic