Creating a Class() example in Kotlin

Categories:
less than a minute
In Object-Oriented Programming Languages, the classes are important. You can find a simple Class creating example in this post.
fun main() {
var personA = Person("Mike","Sunshine")
var personB = Person()
var personC = Person(lastName = "Peterson")
}
class Person (firstName:String ="John" , lastName:String="Doe"){
init {
println("A new person object created with First Name: $firstName and " +
"Last Name: $lastName" )
}
}
A new person object created with First Name: Mike and Last Name: Sunshine
A new person object created with First Name: John and Last Name: Doe
A new person object created with First Name: John and Last Name: Peterson
Process finished with exit code 0
```
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.