Types of Constructor in Kotlin

Constructor in Kotlin:

Parameters in Kotlin are a bit different from Java. As you can see, we first write the name of the parameter and then its type.

fun add(x: Int, y: Int) : Int {
return x + y
}

An extremely useful thing about parameters is that we can make them optional by specifying a default value. Here is an example of a function you could create in an activity, which uses a toast to show a message:

fun toast(message: String, length: Int = Toast.LENGTH_SHORT) {
Toast.makeText(this, message, length).show()
}