June 2018
Intermediate to advanced
310 pages
6h 32m
English
Exactly like in Java, abstract classes are marked by abstract and interfaces by the interface keyword:
abstract class AbstractDungeonMaster { abstract val gameName: String fun startGame() { println("Game $gameName has started!") }}interface Dragon
As in Java 8, interfaces in Kotlin can have a default implementation of functions, as long as they don't rely on any state:
interface Greeter { fun sayHello() { println("Hello") }}
There are no inherits and implements keywords in Kotlin. Instead, both the name of an abstract class and all the names of the interfaces that class implements are put after a colon:
class DungeonMaster: Greeter, AbstractDungeonMaster() { override val gameName: String get() = "Dungeon of the Beholder"}
We ...
Read now
Unlock full access