February 2018
Intermediate to advanced
350 pages
7h 35m
English
There is a big difference between member functions and extension functions when we talk about inheritance.
The open class Canine has a subclass, Dog. A standalone function, printSpeak, receives a parameter of type Canine and prints the content of the result of the function speak(): String:
open class Canine { open fun speak() = "<generic canine noise>"}class Dog : Canine() { override fun speak() = "woof!!"}fun printSpeak(canine: Canine) { println(canine.speak())}
We already covered this in Chapter 1, Kotlin – Data Types, Objects and Classes, in the Inheritance section. Open classes with open methods (member functions) can be extended and alter their behavior. Invoking the speak function will act differently ...
Read now
Unlock full access