Creating a 'Person' class with name and age properties

Report a typo

You need to create an object of a 'Person' class in Kotlin. The 'Person' class should have two properties: 'name' of type String and 'age' of type Int. When an instance of the 'Person' class is created, it should automatically print a statement displaying the 'name' and the 'age'. Fill the blanks in the given code to implement the required functionality.

Fill in the gaps with the relevant elements
class ( name: String, val age: Int) {
     {
        println("Person instance is created with name = $name and age = $age")
    }
}
fun main() {
    val person = Person(name = "John", age = 25)
}
initPersonval
___

Create a free account to access the full topic