Complete the code to declare a data class named User with two properties.
data class User(val name: String, val [1]: Int)
The data class User has two properties: name and age. 'age' is the correct property name for an integer representing the user's age.
Complete the code to create an instance of the User data class.
val user = User(name = "Alice", [1] = 30)
When creating an instance of User, the property 'age' must be assigned an integer value. Here, 30 is assigned to 'age'.
Fix the error in the copy function call to change the age of the user.
val olderUser = user.copy([1] = 31)
The copy function allows creating a new User with some properties changed. To change the age, use 'age = 31'.
Fill both blanks to define a data class with a default value for age.
data class User(val name: String, val age: Int = [1]) { fun isAdult() = age [2] 18 }
The default age is set to 18. The function checks if age is greater than 18 to determine adulthood.
Fill all three blanks to create a data class with a method that returns a greeting message.
data class User(val name: String, val age: Int) { fun greet() = "Hello, my name is [1] and I am [2] years [3]." }
The greet function uses 'name' and 'age' properties to create a greeting. The word 'old' completes the sentence.