open class Person( open var age: Int, name: String) {
init {
println("My name is $name.")
println("My age is $age")
}
}
class MathTeacher( override var age :Int, var name : String): Person(age,name) {
fun teachMaths() {
println("I teach in primary school $age")
}
}
class Footballer(age: Int, name: String): Person(age, name) {
fun playFootball() {
println(“I play for LA Galaxy.”)
}
}
fun main(args: Array) {
val t1 = MathTeacher(25, “Jack”)
t1.teachMaths()
println(t1.age)
println()
val f1 = Footballer(29, "Christiano")
f1.playFootball()
}
So The issue is when I call the maths teacher constructor, it supposedly calls the person class constructor which then initializes the variables
Shouldn’t I be getting null values when I print since my subclass constructor hasn’t run yet