October 2018
Intermediate to advanced
370 pages
9h 15m
English
As we know, a class can implement more than one interface. What happens if two interfaces have the same signatures; how can we choose one of these functions? To understand this concept, we need to create another interface called IFlyable with two functions—fly and engineStart. We can implement the engineStart function and define the fly function as follows:
interface IFlyable { fun startEngine(){ println("Jet engine is ready ...") } fun fly() }
Let the Car class implement the IFlyable interface to create an advanced vehicle that can drive and fly:
class Car(override var numberOfDoors: Int, val name : String) : IDriveable, IFlyable { override fun startEngine() { } override fun fly() { println("$name ...Read now
Unlock full access