Medium
open class Base(val name: String) {
init { println("Initializing Base") }
open val size: Int =
name.length.also { println("Initializing size in Base: $it") }
}
class Derived(
name: String,
val lastName: String
) : Base(name.capitalize().also { println("Argument for Base: $it") }) {
init { println("Initializing Derived") }
override val size: Int =
(super.size + lastName.length).also { println("Initializing size in Derived: $it") }
}
Executingval derived= Derived("jean","Dupont"), outputs:
Edit
0
Community EvaluationsNo one has reviewed this question yet, be the first!
10
How to flatten a list of lists in Kotlin3
Write a Kotlin program that evaluates an arithmetic expression.6
Write a function that returns the maximum of two integers in Kotlin4
Create a data class with a vip property implementing the Human interface5
Kotlin: Compile the following code and see the error.2
Write a Kotlin code that prints 7 to the console.2
In Kotlin, adding an element to a list does not change the list.