[Kotlin] Class
class Person (val name: String, var age: Int) { init {} fun greeting(pn: String) { println("$name says hello to $pn") } } fun main() { val p = Person("Jack", 23) p.greeting("Wan") }
With named parameters:
class Person (val name: String = "", var age: Int = 23) { init {} fun greeting(pn: String) { println("$name says hello to $pn") } }
fun main() { val p = Person(age=23, name="Jack") p.greeting("Wan") }