A class is a blue print defined which groups functions and properties. Classes in Kotlin are defined using the keyword class followed by the class name. The body goes inside the curly braces.
Syntax of class in Kotlin
An instance of the class is instantiated in the following way
instance of the class
Contrary to Java, new isn’t a keyword in Kotlin.
new is not a keyword
Continue reading Class
A visibility modifier (a.k.a access modifiers or access specifiers) is a concept not tied to any specific programming language. It is a language keyword that precedes a declaration and defines the scope from where it is visible -thus can be accessed. Visibility Modifiers are modifiers that when appended to a class, interface, property or function in Kotlin, would define where all it is visible and from where all it can be accessed. The setters of properties in Kotlin can have a separate modifier from the property. There are four visibility modifiers in Kotlin
Continue reading Visibility Modifiers
In most programming language, we must specify all the arguments that a function accepts while calling that function. In Kotlin, we have a feature using which we can get rid of this constraint. We can make parameter optional while calling the function. i.e. we may pass or not pass while an argument while calling function.
Continue reading Default And Named Arguments
Every Kotlin program has at least one function main(). However, you can define any number of functions in your program until memory is not full. It’s always a good practice to divide the whole program into smaller functions that are logically similar. It makes program more readable, understandable and debuggable.
A function declaration is done using the fun keyword.
The basic syntax of a function in Kotlin looks like this:
Syntax of for loop
Continue reading Functions
An Array is a collection of a values of the same type. When you need to store a list of values, such as numbers, you can store them in an array, insted of declaring separate variables for each number.
Constructor of Array in Kotlin
Syntax of Array in Kotlin
As you can see, constructor of array takes a fix size and an init function to return elements of array. There are multiple ways to create a kotlin array
- Using Library function
- Using Array Constructor
- Using Factory function
Continue reading Array of Kotlin
The for loop iterates through a collection, more specifically through anything that provides an iterator.
Syntax to use for loop in Kotlin.
Continue reading The for Loop