Creating an anonymous object with properties in Kotlin

Report a typo

In Kotlin, you want to create an instance of an anonymous object and assign it to a 'person' variable. This object should have two properties - a read-only ('val') property 'name' with the value 'John', and a mutable ('var') property 'age' with the value 30. You also need to print a message displaying these properties in a specific manner. Fill the blanks in the code to complete this task.

Fill in the gaps with the relevant elements
fun () {
    val person =  {
         name = "John"
        var age = 30
    }
    ("Name: ${person.name}, Age: ${person.age}")
}
printlnmainobjectvar
___

Create a free account to access the full topic