Kotlin Abstract Class

In this tutorial you will learn about the Kotlin Abstract Class and its application with practical example.

Kotlin Abstract Class

An abstract class is class which can not be instantiate it means you can not create an object of abstract class.However we can inherit them from subclass.

Table Of Contents

The members of an abstract class are non-abstract if you don’t declare or explicitly use abstract keyword to make them abstract.

Example :-

Here , Employee is an abstract class which object can not be created.

Salary is non-abstract property and displaySal is non-abstract method. If you want to override these members so you need to declare them “open”.

displayJob is abstract method. This function must be overridden in subclass,it doesn’t have any implementation

We don’t need to declare abstract class as “open” because abstract classes are always open.

Example: Let’s get understand Kotlin Abstraction by below example. Check below code.

Output: The output of above code will look like below image.

kotlin-abstract

In this tutorial we have learn about the Kotlin Abstract Class and its application with practical example. I hope you will like this tutorial.