October 2018
Intermediate to advanced
370 pages
9h 15m
English
Redefining the inherited function in a child class is called overriding. The purpose of function-overriding is to allow the derived class to give its own implementation because the provided implementation is not sufficient. In Kotlin, there are few rules to override a function:
Let's add the displayInfo() function in the Student class and include more information using the print function. This works as follows:
open class Person(pName: String, pAge: Int) { var name = pName var age = pAge open fun displayInfo(){ println("My name is $name, I am $age years old.") }}class Student(name: String, age: Int, id ...
Read now
Unlock full access