You are here
Home > Kotlin

Kotlin: Inheritance

Inheritance In this post we will discuss Inheritance in kotlin with example. Inheritance provides the reusability of the previously defined functions. The previously defined class is called super(base, parent) class and the class that inherits the super class called the sub(derived, child) class. A derived class implicitly get all the parent

Kotlin: Interfaces

Interfaces In this post we will discuss Interfaces in kotlin, use of it, and how to declare interface in kotlin. Interface only have function declaration it not contains its implementation. In kotlin interface is by default open. You have to use override keyword in class to implement its function. If you

Kotlin: Companion Object

Companion Object In this post we will discuss companion object in kotlin. Kotlin not support static methods and variable so we use companion object to make variable and methods static. The companion objects are declared inside a class using companion The function declared inside a companion object are called using

Kotlin: Enum Class

Kotlin: Enum Class In this post we will discuss Enum Class in kotlin. Enumeration is a special type of class, if class is enum type then it is limited to a set of predefined constants. To declare a class as enum use enum keyword before the class Example: enum class Direction { North,South,West,East } fun main(args:Array<String>) { var

Kotlin:Data Class

Data Class In this post we will discuss Data classes with example. We frequently create a class to do nothing but hold data. Kotlin provides similar concept, called data class and marked as data. When we use data class the primary constructor only accepts property variables such as val or var

Kotlin Secondary Constructor

Kotlin Secondary Constructor In previous post we discussed kotlin classes and primary constructor. And in this post we will discuss how to defined secondary constructor in kotlin classes. Kotlin Secondary Constructor For declaration of secondary constructor use constructor keyword: class Employee {                        constructor(parent: Employee) { parent.children.add(this) } } If the class has a primary constructor, each secondary constructor

Referential equality and Structural equality

Referential equality and Structural equality In this post of kotlin we will discuss Referential equality and Structural equality, packages, imports, kotlin is operator. Referential equality and Structural equality When we work will object-oriented programming, there are two types of quality comes one is referential equality and structural equality. Referential equality comes when two

Top