Using the super keyword

So far, all classes were inherited using a primary constructor. If the Student class doesn't have a primary constructor but a secondary constructor instead, the secondary constructor can be preceded by the super keyword:

class Student: Person {

constructor(fName: String,lName: String, age: Int, id: String) : super(fName,lName,age, id)

fun aboutEducation(){
println("I am a student of Computer Science.")
}

fun attendLectures() {
println("I am studding Introduction to Kotlin lecture.")
}
}

The super keyword will call the constructor of the super or parent class to initialize the properties of the parent class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.183.210