Complete the code to declare a class named Person.
class [1] { var name: String = "" }
The class name should start with a capital letter and match the concept, so Person is correct.
Complete the code to add a function greet() that prints a greeting.
class Person { var name: String = "" fun [1]() { println("Hello, $name!") } }
The function name greet matches the instruction to add a greet() function.
Fix the error in the code to correctly initialize the name property via constructor.
class Person([1]: String) { var name: String = name }
Using val name: String in the constructor declares and initializes the property properly.
Fill both blanks to create a class with a mutable property and a function that updates it.
class Counter { var count: Int = [1] fun increment() { count [2] 1 } }
The count starts at 0 and is increased by 1 using the '+=' operator.
Fill all three blanks to define a class with a property, a constructor, and a method that returns a greeting.
class Person([1]: String) { val name: String = [2] fun greet(): String { return "Hello, $[3]!" } }
The constructor parameter, property, and string interpolation all use the same name 'name' to connect the data.