October 2018
Intermediate to advanced
370 pages
9h 15m
English
An abstract function is a function without a function body. To understand this concept, let's take the example of the Shape class:
abstract class Shape(val name: String) { init { println("Drawing $name") } open fun draw(){} open fun getArea() : Double{ return 0.0 } }
The Shape abstract class contains two normal functions: draw and getArea. Both functions are open and available for inheritance. Having non-abstract functions in an abstract class, however, does have some drawbacks. If a function is a normal or non-abstract function, it must provide a function body even if it is empty. If a child class inherits a parent class, it won't know whether it is necessary to provide an implementation of the inherited functions.
Read now
Unlock full access