Abstract Classes

Abstract classes provide another way to enforce structure in your classes. An abstract class is never instantiated. Its purpose is to provide function implementations through inheritance to subclasses that are instantiated.

An abstract class is defined by prepending the abstract keyword to a class definition. In addition to function implementations, abstract classes can include abstract functions – function declarations without implementations.

It is time to give the player something to fight in NyetHack. Add an abstract class called Monster to Creature.kt. Monster implements the Fightable interface, and therefore needs a healthPoints property and an attack function. (What about the other Fightable properties? ...

Get Kotlin Programming: The Big Nerd Ranch Guide, First Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.