October 2018
Intermediate to advanced
370 pages
9h 15m
English
Let's create another child class, Alien, and extend it from the Student class. Override the displayInfo function and add a print message:
class Alien (name: String, age: Int, id : Int, education : String, institution : String): Student(name, age, id, education, institution){ override fun displayInfo() { super.displayInfo() println("I know everything") }}fun main(args: Array<String>) { val alien = Alien(name = "Alien eli", age = 225, id = 10101, education = "Computer Virus", institution = "Pluto") alien.displayInfo()}
Don't forget to open the Student class so that the Alien class can extend it. However, we can see that we don't need to add the open keyword with the displayInfo() function in the Student class. Once the function ...
Read now
Unlock full access