June 2018
Intermediate to advanced
310 pages
6h 32m
English
Our DungeonMaster looks a bit awkward now, since it can proclaim the start of only one game. Let's add a non-empty constructor to our abstract class to fix that:
abstract class AbstractDungeonMaster(private val gameName : String) { fun startGame() { println("Game $gameName has started!") }}
Now, our DungeonMaster must receive the name of the game and pass it to the abstract class:
open class DungeonMaster(gameName: String): Greeter, AbstractDungeonMaster(gameName)
What if we wanted to extend DungeonMaster by having an EvilDungeonMaster?
In Java, all classes can be extended, unless they're marked final. In Kotlin, no class can be extended, unless it's marked open. The same goes for functions in abstract classes. That's the reason ...
Read now
Unlock full access