Kotlin OOPs Concept

Kotlin Data Classes

This tutorial is about Kotlin Data classes, requirements that data class must fulfill, and their standard functionalities. Data Classes Data classes  are classes whose main purpose is to hold data/state and contains standard functionalities. A data keyword is used to declare a class as a data class. Example: data class Student(val name: String, val age: Int) …

Kotlin Data Classes Read More »

Kotlin Object Declarations and Expressions

This tutorial is about object declarations (singletons) and object expressions with the help of examples. Object Declarations Object declarations defines singletons. Singleton is an object-oriented pattern where a class can have only one instance (object) at a time. Kotlin creates singletons with the object keyword. The object declaration can have functions, properties, and the init …

Kotlin Object Declarations and Expressions Read More »

Kotlin Companion objects

This tutorial is about companion objects in Kotlin with the help of examples. Kotlin doesn’t have a static keyword. Static members belong to a type, and not to an instance of a type. In kotlin to achieve this static feature, we make use of companion object. companion object An object declaration inside a class can be …

Kotlin Companion objects Read More »

Kotlin Getters and Setters

This tutorial is about how to use getters and setters in Kotlin with the help of simple example. Getters and Setters Getters are used for getting value of the property and Setters are used for setting the value of the property. Setters can have visibility modifiers but Getters always have the same visibility as the …

Kotlin Getters and Setters Read More »

Kotlin Visibility Modifiers

This post is about Access/Visibility modifiers in kotlin and how to use them. Access Modifiers In Kotlin, visibility modifiers are used to restrict the accessibility of Classes, objects, interfaces, constructors, functions, properties and their setters to a certain level. Getters always have the same visibility as the property. There are four visibility modifiers in Kotlin: public protected internal …

Kotlin Visibility Modifiers Read More »

Kotlin Interfaces(With Examples)

This article is about interfaces and how to implement it in Kotlin with the help of simple examples. Interfaces In Kotlin, Interfaces can contain declarations of abstract methods (have no body), as well as method implementation of non-abstract methods.  Interfaces can have properties but these need to be abstract or to provide accessor implementations. Creating …

Kotlin Interfaces(With Examples) Read More »

Kotlin Abstract Classes and Abstract Members

In this article, you will learn about Kotlin abstract classes, abstract methods and how to use them in our program with the help of examples. Abstract Classes An abstract class is a class that cannot be instantiated (we cannot create objects of an abstract class). Syntax We use the abstract keyword to declare an abstract class. abstract class className …

Kotlin Abstract Classes and Abstract Members Read More »

Kotlin Constructor in Inheritance

In this article, you will learn about Constructors (both primary and secondary constructor) behavior in Inheritance, in Kotlin with the help of examples. A constructor for a class is a special member function, which is called implicitly, just after the memory is allocated for the object to initialize the properties of the newly created object …

Kotlin Constructor in Inheritance Read More »

Kotlin Inheritance

In this tutorial, we will learn about Inheritance in Kotlin with the help of examples. Inheritance Inheritance is one of the key feature of OOP (Object Oriented Programming). Inheritance can be defined as the process where one class is allowed to inherit the features (properties and functions) of another class. The class which inherits the features of other …

Kotlin Inheritance Read More »

Kotlin Extension Function

In this article, you will learn to extend a class with new functionality using extension functions. Extension Function Kotlin provides the ability to add methods to the existing classes without having to inherit from the class or use design patterns such as Decorator to do this. This is achieved using special declarations called extensions. Using …

Kotlin Extension Function Read More »