Kotlin Program using primary constructor
In this program, You will learn how to implement the primary constructor in Kotlin.
class Test(var name: String, var sal: Int) {
//statement
}
Example: How to implement primary constructor in Kotlin.
class Test(var ename: String, var sal: Int) {
fun change() {
sal += 100
}
}
fun main(args: Array<String>) {
var obj = Test("john", 5000)
obj.change()
println("Employee name is:${obj.ename}")
println("Employee salary is:${obj.sal}")
}
Output:
Employee name is:john
Employee salary is:5100