Kotlin Functions
Kotlin Functions - Important Points
21. | What is a default argument in Kotlin? |
---|
A. An argument that is required to be passed to a function
B. An argument that is passed using a named parameter
C. An argument that has a default value specified in the function declaration
D. An argument that is passed using a lambda expression
View Answer Discuss Work SpaceAnswer: option c
Explanation:
A default argument in Kotlin is an argument that has a default value specified in the function declaration, so it can be omitted when calling the function.
22. | Which of the following is a valid way to call a function with named arguments in Kotlin? |
---|
A. sum(1, 2, x = { x, y -> x + y })
B. sum(1, 2, op = { x, y -> x + y })
C. sum(1, 2, { x, y -> x + y }, op = true)
D. sum(x = 1, y = 2) { x, y -> x + y }
View Answer Discuss Work SpaceAnswer: option d
Explanation:
Option D is a valid way to call a function with named arguments in Kotlin, by specifying the name of each argument and its corresponding value in the function call.