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 542 times
Edit
2
Community EvaluationsNo one has reviewed this question yet, be the first!
7
How to flatten a list of lists in Kotlin5
Write a function that returns the maximum of two integers in Kotlin1
In Kotlin, adding an element to a list does not change the list.2
Print the value of a nullable string in Kotlin4
Kotlin: Compile the following code and see the error.3
Write a Kotlin program that evaluates an arithmetic expression.2
Concatenate two strings in Kotlin