Kotlin Functions
Kotlin Functions - Important Points
1. | What is the keyword used to define a function in Kotlin? |
---|
A. fun
B. function
C. define
D. declare
View Answer Discuss Work SpaceAnswer: option a
Explanation:
2. | Which of the following is not a valid function declaration in Kotlin? |
---|
A. fun add(x: Int, y: Int): Int = x + y
B. fun add(x: Int, y: Int) = x + y
C. fun add(x: Int, y: Int): Unit = println(x + y)
D. fun add(x: Int, y: Int): Int => x + y
View Answer Discuss Work SpaceAnswer: option d
Explanation:
3. | How is a function that takes no arguments declared in Kotlin? |
---|
A. fun noArgs()
B. fun noArgs(): Unit
C. fun noArgs(): Void
D. fun noArgs(): Nothing
View Answer Discuss Work SpaceAnswer: option b
Explanation:
4. | What is a higher-order function in Kotlin? |
---|
A. A function that returns a value
B. A function that takes another function as a parameter or returns a function as a result
C. A function that has a variable number of arguments
D. A function that can be called without any arguments
View Answer Discuss Work SpaceAnswer: option b
Explanation:
5. | Which of the following is not a valid way to call a function in Kotlin? |
---|
A. add(1, 2)
B. add(x = 1, y = 2)
C. add(y = 2, x = 1)
D. x.add(2)
View Answer Discuss Work SpaceAnswer: option d
Explanation: