January 2017
Intermediate to advanced
420 pages
9h 25m
English
You decided your new class has to redefine one of the methods inherited from one of the parent classes. This is known as overriding; I have already used it in the previous chapter. If you have already programmed in Java, you will find Kotlin a more explicit language. In Java, every method is virtual by default; therefore, each method can be overridden by any derived class. In Kotlin, you would have to tag the function as being opened to redefine it. To do so, you need to add the open keyword as a prefix to the method definition, and when you redefine the method, you specifically have to mark it using the override keyword:
abstract class SingleEngineAirplane protected constructor() { abstract fun fly() } class CesnaAirplane : SingleEngineAirplane() ...Read now
Unlock full access