October 2018
Intermediate to advanced
370 pages
9h 15m
English
Inheritance is a method in which a child class can access all the functions and properties of its parent class. What if, however, the derived class wants its own specific implantation of the function that is already provided by the derived class? To understand this problem, let's take a simple example of a Person class with two properties, name and age, and a function, displayInfo():
open class Person(pName: String, pAge: Int) { var name = pName var age = pAge fun displayInfo(){ println("My name is $name, I am $age old. ") }}
Create another class called Student with some extra properties (id, education, and institute name) and extend it with the Person class:
class Student(name: String, age: Int, id : Int, education : String, institution ...Read now
Unlock full access