July 2018
Intermediate to advanced
400 pages
12h 14m
English
To use an interface, we say that you “implement” it on a class. There are two parts to this: First, you declare that the class implements the interface. Then, you must ensure that the class provides implementations for all of the properties and functions specified in the interface.
Use the : operator to implement the Fightable interface on Player.
Listing 16.2 Implementing an interface (Player.kt)
class Player(_name: String,
override var healthPoints: Int = 100,
var isBlessed: Boolean = false,
private var isImmortal: Boolean) : Fightable {
...
}
When you add the Fightable interface to Player, IntelliJ indicates that functions and properties are missing. Warning you that properties and functions ...