Medium
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 607 times
Edit
2
Community EvaluationsNo one has reviewed this question yet, be the first!
10
How to flatten a list of lists in Kotlin6
Write a function that returns the maximum of two integers in Kotlin2
Write a Kotlin code that prints 7 to the console.5
Kotlin: Compile the following code and see the error.2
In Kotlin, adding an element to a list does not change the list.4
Create a data class with a vip property implementing the Human interface3
Write a Kotlin program that evaluates an arithmetic expression.