linkedin-skill-assessments-quizzes

Scala

Q1. Scala bytecode can run on top of Java VM. What is the fundamental difference between Java object.clone() and Scala object.copy()?

Q2. What value does this code return?

val m1 = Map("a"->1,"b"->2,"c"->3)
m1("a")

Q3. What is one way to avoid low-level parallelization details?

Q4. What do you use in ScalaTest to see a detailed diagram of error messages when a test fails?

Q5. What data type would you use to store an immutable collection of objects that contain a fixed number of varying types?

Q6. After defining a function in the interpreter, Scala returns the following. What does the () indicate?

myfnc: ()Unit

Q7. What type of number is 1234.e5?

Q8. When you convert a map to a list using the toList method of the map, the result will be of which type?

Q9. What type of object does this code create?

val x = (1234, "Active")

Q10. Which is a subclass of all classes?

Null in Scala Standard library. The question is a bit incorrect - Null is a subtype of every type except those of value classes

Q11. For the for-yield construct, is the scope separate between for-body and yield-body?

Example: yield-body has access to the e variable from the for-body

val a = Array(1, 2, 3, 4, 5)
for {
     e <- a if e > 2
} yield e

Q12. What is one way to implement pattern matching on methods?

Note: ambiguous question, it’s not clear what kind of pattern matching is meant here.

Q13. What is the value of z after executing this code?

val y = List('a','b')
val z = y::List('c')

Q14. What term is used to specify a precondition?

Q15. Which Scala type may throw an exception or a successfully computed value, and is commonly used to trap and propagate errors?

scala.util.Try

Q16. What is the data type of y after this code is executed?

val y = (math floor 3.1415 * 2)

Q17. When using pattern matching, which character matches on any object?

Pattern Matching

Q18. You have created an array using val. Can you change the value of any element of the array—and why or why not?

Explanation:

val a1 = Array(1, 2, 3)
a1{1} = 3 // OK
a1 = Array(1, 3, 3) // error: reassignment to val

Q19. What is the output of this function?

def main () {
     var a = 0
     for (a<-1 until 5){println(a)}

Q20. What do you call objects with immutable state?

Note: singletons may have mutable state

Q21. You have written a Scala script. How would you access command-line arguments in the script?

Q22. What does this code return? val x = 3; if (x > 2) x = 4 else x = x*2

Q23. Which statement returns a success or a failure indicator when you execute this code?

val MyFuture = Future {runBackgroundFunction() }

Q24. To denote a parameter that may be repeated, what should you place after type?

Q25. What is called when a superclass has more than one subclass in Scala?

Q26. One way to improve code reliability is to use __ , which will evaluate a condition and return an error if the condition is violated.

Q27. Which statement about if-else-if-else statements is true?

Q28. What do you call the process of changing the definition of an inherited method?

Q29. To denote a parameter that may be repeated, what should you place after the type?

Repeated Parameters in Scala

Q30. What is the code below equivalent to?

myClass.foreach(println _)

Q31. What is an advantage of an immutable object?

Q32. You want to create an iteration loop that tests the condition at the end of the loop body. Which iteration would you use?

Q33. What can you use to make querying a database more efficient, by avoiding the need to parse the SQL string every time a query is executed from Scala?

PreparedStatement from Java which is also used in Scala

Q34. Which is not a member of the collections hierarchy?

Q35. Which term makes the contents of packages available without prefixing?

Q36. If you wanted to find the remainder after division, what operator would you use?

Q37. What are defined inside a class definition?

Q38. What defines methods and fields that can then be reused by mixing into classes?

Q39. When do you need to explicitly state the return type in a function definition?

Q40. Why would you make a field private?

Q41. What’s the difference between .equals and ==?

Source:

Q42. What is denotes the intersection between two sets?

Source:

Q43. What’s the best way to execute code in the background in a separate thread?

Q44. What do you call a function defined in a block?

Q45. What do you call a Scala method that is parametrized by type as well as by value?

Q46. What type of exception is thrown when a precondition is violated?

Q47. In scala what is precondition?

Q48. What would you change in this code to make it execute in parallel?

 val myNums = (1 to 500).toList
 list.map(_ + 1)

Q49. What is a free variable?

Q50. What is the difference between .equals() and == ?

Q51. What’s the best way to execute code in the background in a separate thread?

Q53. What value does this code return?

x= List(1,2,4); x(1)?