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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.