Hard
Considering :
open class Animal
data class Cat(val name : String = "Kitty") : Animal()
The following code :
val cats: MutableList<Cat> = mutableListOf(Cat("Isidor"), Cat("Garfield"), Cat("Rogue"))
val animals: List<Animal> = cats
cats.add(Cat())
animals.forEach({ print(it) })
Author: W3D TeamStatus: PublishedQuestion passed 484 times
Edit
Similar QuestionsMore questions about Kotlin
6
How to flatten a list of lists in Kotlin2
Write a function that returns the maximum of two integers in Kotlin2
Kotlin: Compile the following code and see the error.1
Write a Kotlin program that evaluates an arithmetic expression.1
Create a data class with a vip property implementing the Human interface