-
-
Save pradhuman7d1/f870e21851f8c987794c1000b9f76d05 to your computer and use it in GitHub Desktop.
scala-functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q. What is unit return type? | |
A. unit is used whenever we don't need to return a value. | |
Q. val p = pow _ ; what is p storing here? | |
A. p is storing the function pow and this is an example of higher order functions. | |
Q. What are closures? | |
A. Closures are special functions that can access and use values declared outside of it. | |
Q. What are anonymous functions? | |
A. Functions that does not contains any name and are short to declare. Used when we need functions inline. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q. What is the keyword to declare a function? | |
a. fn | |
b. fun | |
c. dec | |
d. def | |
A. d. def | |
Q. val p = pow _ ; what this _ signifies? | |
a. return nothing (unit) | |
b. return answer | |
c. return function | |
d. return power of p | |
A. c. return function | |
Q. The following code is an example of ? | |
val p = 10 | |
def example(a:double) = a*p / 100 | |
a. Anonymous Function | |
b. Higher Order Function | |
c. Closure | |
d. none of these | |
A. c. Closure | |
Q. What is the correct syntax to declare variable arguments in a function? | |
a. (args: Int) | |
b. (args...) | |
c. (varargs) | |
d. (args: Int*) | |
A. d. (args: Int*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment