Kotlin Functions
Kotlin Functions - Important Points
6. | What is the return type of a function that does not return a value in Kotlin? |
---|
A. Int
B. Unit
C. Void
D. Nothing
View Answer Discuss Work SpaceAnswer: option b
Explanation:
7. | What is the purpose of the 'infix' modifier in a function declaration in Kotlin? |
---|
A. It allows the function to be called with or without argument names
B. It allows the function to be called using infix notation
C. It allows the function to be called with a variable number of arguments
D. It allows the function to be called using prefix notation
View Answer Discuss Work SpaceAnswer: option b
Explanation:
8. | Which of the following is not a valid way to define a function with a variable number of arguments in Kotlin? |
---|
A. fun sum(vararg nums: Int): Int = nums.sum()
B. fun sum(nums: Array
C. fun sum(nums: List
D. fun sum(nums: Set
Answer: option b
Explanation:
9. | What is the purpose of the 'tailrec' modifier in a recursive function in Kotlin? |
---|
A. It allows the function to be called using tail recursion optimization
B. It allows the function to be called with a variable number of arguments
C. It allows the function to be called with or without argument names
D. It allows the function to be called using infix notation
View Answer Discuss Work SpaceAnswer: option a
Explanation:
10. | Which of the following is a valid way to declare and call an anonymous function in Kotlin? |
---|
A. { x: Int, y: Int -> x + y } (1, 2)
B. fun(x: Int, y: Int): Int { return x + y }(1, 2)
C. fun(x: Int, y: Int) = x + y (1, 2)
D. { x, y -> x + y }(1, 2)
View Answer Discuss Work SpaceAnswer: option d
Explanation: