Kotlin Terminology

Kotlin Vocabulary - Classes and Inheritance in Kotlin

Kotlin Terminology

Class hierarchy - An arrangement where classes are organized in a hierarchy of parents and children. Hierarchy diagrams are usually drawn with the parents shown above children.

Child or subclass - Any class that is below another class in the hierarchy.

Parent or superclass or base class - Any class with one or more child classes.

Root or top-level class - The class at the top (or root) of the class hierarchy.

Inheritance - When a child class includes (or inherits) all the properties and methods of its parent class. This allows you to share and reuse code, which makes programs easier to understand and maintain.

Inheritance in Android Classes

2fbc991a6afe5299.png

Class hierarchy diagram 57cd75bd819126bb.png

An "abstract" class is a class that cannot be instantiated because it is not fully implemented. You can think of it as a sketch. A sketch incorporates the ideas and plans for something, but not usually enough information to build it. You use a sketch (abstract class) to create a blueprint (class) from which you build the actual object instance.

When you are working with a specific instance of a class and need to access multiple properties and functions of that instance, you can say "do all the following operations with this instance object" using a with statement. Start with the keyword with, followed by the instance name in parentheses, followed by curly braces which contain the operations you want to perform.

with (instanceName) {
    // all operations to do with instanceName
}

By default, in Kotlin, classes are final and cannot be subclassed. You are only allowed to inherit from abstract classes or classes that are marked with the open keyword

Did you find this article valuable?

Support Manish Bannur by becoming a sponsor. Any amount is appreciated!