Reputation: 183
like this:
open class Father(
val name:String = ""
)
data class Son(
val age:Int = 1
):Father()
fun main(args: Array<String>) {
val son = Son(
name = "",
age = 10
)
}
I cannot init "name" attribute of Son because of it is from Parent Class Father. How can I fix this?
Upvotes: 1
Views: 239
Reputation: 13288
It should be
open class Father(open val name: String="")
data class Son(val age: Int = 1,
override val name: String ) : Father(name)
fun main(args: Array<String>) {
val son = Son(name = "",age = 10)
}
Upvotes: 2