Abstract classes

Abstract classes are used to define behavior but not implement it. Implementation of a certain behavior is kept open so that it can be overridden by any implementation later. Let's look at the Animal class in the following code:

public abstract class Animal() {

open fun makeNoise(): String? {
return null;
}

open fun name(): String? {
return null;
}
}

The preceding class is marked as abstract so no instance can be created out of it. Instead, it is meant to be extended and its behavior will override by some other class. Functions of that class, such as makeNoise and name, are kept open with the corresponding keyword so that any subclass implementation can override it later on. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.103.204