Kotlin Functions
Kotlin Functions - Important Points
16. | Which of the following is a valid way to call a higher-order function in Kotlin? |
---|
A. sum(1, 2) { x, y -> x + y }
B. sum(1, 2) { x -> x * x }
C. sum(1, 2, { x, y -> x + y })
D. sum(1, 2, { x -> x * x })
View Answer Discuss Work SpaceAnswer: option c
Explanation:
17. | What is the purpose of the 'operator' modifier in a function declaration in Kotlin? |
---|
A. It allows the function to be called using infix notation
B. It allows the function to be inlined at the call site to improve performance
C. It allows the function to be called with a variable number of arguments
D. It allows the function to be used as an overloaded operator
View Answer Discuss Work SpaceAnswer: option d
Explanation:
18. | What is a lambda expression in Kotlin? |
---|
A. A named function
B. A higher-order function
C. An anonymous function
D. A function with a single expression
View Answer Discuss Work SpaceAnswer: option c
Explanation:
19. | What is the purpose of the 'crossinline' modifier in a function declaration in Kotlin? |
---|
A. It allows the function to be called using infix notation
B. It specifies that the function should not have a return value
C. It specifies that the function should not have a receiver parameter
D. It prevents the use of non-local returns in the function body
View Answer Discuss Work SpaceAnswer: option d
Explanation:
20. | Which of the following is a valid way to declare an extension function in Kotlin? |
---|
A. fun String.capitalize(): String = this.toUpperCase()
B. fun capitalize(String str): String = str.toUpperCase()
C. fun String.capitalize(): String = toUpperCase()
D. fun capitalize(str: String): String = str.toUpperCase()
View Answer Discuss Work SpaceAnswer: option a
Explanation: