Book Image

Programming Kotlin

Book Image

Programming Kotlin

Overview of this book

Quickly learn the fundamentals of the Kotlin language and see it in action on the web. Easy to follow and covering the full set of programming features, this book will get you fluent in Kotlin for Android.
Table of Contents (20 chapters)
Programming Kotlin
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Abstract classes


Adding the abstract keyword in front of the class definition will mark the class as abstract. An abstract class is a partially defined class; properties and methods that have no implementation must be implemented in a derived class, unless the derived class is meant to be an abstract class as well. Here is how you would define an abstract class in Kotlin:

    abstract class A { 
      abstract fun doSomething() 
    } 

Unlike interfaces, you have to mark the function abstract if you don't provide a body definition.

You cannot create an instance of an abstract class. The role of such a class is to provide a common set of methods that multiple derived classes share. The best example of such a case is the InputStream class. This will be very familiar to a developer who has already worked with Java. The JDK documentation says: "This abstract class is the superclass of all classes representing an input stream of bytes. Applications that need to define a subclass...