Basics of Kotlin

Basics of Kotlin Android Teachers

Basics Of Kotlin android like Variables, Class, Interface & Inheritance. How to declare class & variables and assignment of values to it. This is what we going to learn in this post.

learn below terms in the context of Kotlin

In Previous tutorial we have made sample application with android studio 3.0 you can check out my post Get Started with Kotlin on Android. in this tutorial we will learn some basics of kotlin. let’s started

Basics Of Kotlin

  1. Variables

  2. Classes in Kotlin (Declaration & Constructor )

  3. Interface

  4. Inheritance

  5. Making Objects and assign values


1. Variables

declaring variables are easy in Kotlin Syntax goes to var name : type

now let’s assign some values to it

Data types are supported by Kotlin is listed here


2. Classes in Kotlin

Classes in Kotlin are declared using the keyword class:

Now Little twist is here Kotlin class can have a primary contractor and secondary constructor.

The primary constructor cannot contain any code. Initialization code can be placed in init{} blocks, which are prefixed with the init keyword

Use Constructor in Kotlin

Creating Objects in Kotlin


3. Interface

Interface declaration is Kotlin is given below

Use Interfaces in class

Also, you can use instance of Interface like


4. Inheritance

You can extend any class by using : in Kotlin

In Java

In Kotlin

Same as Java, If the class has a primary constructor, the base type can (and must) be initialized right there, using the parameters of the primary constructor.

so it will be like this

In Java

In Kotlin


5. Making Objects and assign values

let create some objects

no new keyword in Kolin

In Java

where in Kotlin


In this tutorial we learn Basics Of Kotlin and next tutorial we will learn Kotlin Operators

Now in next tutorial, we make sample application with Kotlin. hope you guys enjoy this tutorial and it will be useful as well.

317total visits,10visits today

Related posts

Leave a Comment