O'Reilly logo

Kotlin Programming: The Big Nerd Ranch Guide, First Edition by David Greenhalgh, Josh Skeen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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? ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required