Complete the code to define a companion object function named greet.
class Greeter { companion object { fun [1]() = "Hello from companion" } }
The function name should be greet as specified.
Complete the code to define a top-level function named greet that returns a greeting string.
fun [1]() = "Hello from top-level function"
The top-level function should be named greet to match the greeting purpose.
Fix the error in calling the companion object function greet from class Greeter.
fun main() {
println(Greeter.[1]())
}The companion object function is called using the class name followed by the function name greet.
Fill both blanks to create a companion object function that returns a greeting with a name parameter.
class Greeter { companion object { fun greet([1]: String): String = "Hello, [2]" } }
The parameter name must be the same in the function signature and the string interpolation to work correctly.
Fill all three blanks to create a top-level function that returns a greeting with a name parameter.
fun [1]([2]: String): String = "Hello, $[3]"
The function name is greet, the parameter is name, and the string interpolation uses name.