Kotlin Functions
Kotlin Functions - Important Points
11. | What is the purpose of the 'inline' 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 or without argument names
D. It allows the function to be called with a variable number of arguments
View Answer Discuss Work SpaceAnswer: option b
Explanation:
12. | Which of the following is not a valid way to define a lambda function in Kotlin? |
---|
A. { x: Int, y: Int -> x + y }
B. { x: Int -> x * x }
C. { x -> x * x }
D. fun(x: Int, y: Int): Int = x + y
View Answer Discuss Work SpaceAnswer: option d
Explanation:
13. | 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 allows the function to be inlined at the call site to improve performance
C. It prevents the use of non-local returns in the function body
D. It allows the function to be called with a variable number of arguments
View Answer Discuss Work SpaceAnswer: option c
Explanation:
14. | What is the return type of a function in Kotlin if it does not return any value? |
---|
A. Int
B. Unit
C. Void
D. None
View Answer Discuss Work SpaceAnswer: option b
Explanation:
15. | Which of the following is a valid way to declare a higher-order function in Kotlin? |
---|
A. fun sum(x: Int, y: Int, op: (Int, Int) -> Int): Int = op(x, y)
B. fun sum(x: Int, y: Int, op: Int, Int -> Int): Int = op(x, y)
C. fun sum(x: Int, y: Int, op: Int.(Int) -> Int): Int = x.op(y)
D. fun sum(x: Int, y: Int, op: (Int) -> Int): Int = op(x + y)
View Answer Discuss Work SpaceAnswer: option a
Explanation: