Creating a Class() example in Kotlin

Estimated read time 1 min read

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
Blog Writer

The author shares useful content compiled in the field of informatics and technology on this blog.