Skip to content

Commit

Permalink
Update scala-quiz.md (Ebazhanov#308)
Browse files Browse the repository at this point in the history
ответы по скале и новые вопросы
  • Loading branch information
SergDaut authored Aug 23, 2020
1 parent 35acfeb commit b69d046
Showing 1 changed file with 57 additions and 20 deletions.
77 changes: 57 additions & 20 deletions scala/scala-quiz.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Scala Assessment
- [ ] One is a Java object, the other is a Scala object.
- [ ] clone() will copy class structures but not the data, while copy() will also copy data into new objects.
- [ ] There is no difference.
- [ ] copy() allows you to change values during the copying process; clone() does not.
- [x] copy() allows you to change values during the copying process; clone() does not.


#### Q2. What value does this code return?
Expand All @@ -19,22 +19,22 @@ m1("a")
- [ ] a
- [ ] 2
- [ ] b
- [ ] 1
- [x] 1


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

- [ ] monads
- [ ] literal functions
- [ ] partially applied functions
- [ ] parallel collections
- [x] parallel collections


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

- [ ] ArgumentExceptions
- [ ] AssertionException
- [ ] DiagrammedAssertions
- [x] DiagrammedAssertions
- [ ] JUnit


Expand All @@ -43,7 +43,7 @@ m1("a")
- [ ] Array
- [ ] ImmutableCollection
- [ ] List
- [ ] Tuple
- [x] Tuple


#### Q6. After defining a function in the interpreter, Scala returns the following. What does the
Expand All @@ -54,15 +54,15 @@ myfnc: ()Unit

- [ ] The function has no side effects.
- [ ] The function takes no parameters.
- [ ] The function returns no value.
- [x] The function returns no value.
- [ ] Returning unit types to the function is a closures.


#### Q7. What type of number is 1234.e5?

- [ ] hexadecimal
- [ ] short
- [ ] floating point
- [x] floating point
- [ ] long


Expand All @@ -71,7 +71,7 @@ myfnc: ()Unit
- [ ] List[(String, String)]
- [ ] List[(Array, Array)]
- [ ] List[(Array, Array)]
- [ ] List
- [x] List


#### Q9. What type of object does this code create?
Expand All @@ -82,7 +82,7 @@ val x = (1234, "Active")

- [ ] List
- [ ] Map
- [ ] Tuple
- [x] Tuple
- [ ] Array


Expand All @@ -91,22 +91,22 @@ val x = (1234, "Active")
- [ ] AnyVal
- [ ] AnyRef
- [ ] Method
- [ ] Null
- [x] Null NOT SURE


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

- [ ] Yes and no. It is different depending on the for construct and what it does.
- [x] Yes and no. It is different depending on the for construct and what it does. NOT SURE
- [ ] Yes, because the for section does not expose its scope.
- [ ] No, because for-yield shares the same scope, even though they are within separate curly braces.
- [ ] No, because for-yield shares the same scope, even though they are within separate curly braces.
- [ ] Yes, because they are within different curly braces.


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

- [ ] using regex
- [ ] using monads
- [ ] using string matching
- [x] using string matching
- [ ] using case classes


Expand All @@ -118,14 +118,14 @@ val z = y::List('c')
```

- [ ] List(a,b,c)
- [ ] List(List(a, b), c)
- [x] List(List(a, b), c)
- [ ] List(c,a,b)
- [ ] List(c,List(a,b))


#### Q14. What term is used to specify a precondition?

- [ ] assert
- [x] assert
- [ ] require
- [ ] precondition
- [ ] mustHave
Expand All @@ -134,6 +134,7 @@ val z = y::List('c')
#### Q15. Which Scala type may throw an exception or a successfully computed value, and is commonly used to trap and propagate errors?

##### answers missing
Answer should be Option: Some or None


#### Q16. What is the data type of y after this code is executed?
Expand All @@ -142,7 +143,7 @@ val z = y::List('c')
val y = (math floor 3.1415 * 2)
```
- [ ] short
- [ ] double
- [x] double
- [ ] int
- [ ] bigInt

Expand All @@ -151,14 +152,14 @@ val y = (math floor 3.1415 * 2)
- [ ] %
- [ ] _
- [ ] ^
- [ ] *
- [x] *


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

- [ ] Yes, the reference to the array is immutable, so the location that the array points to is immutable. The values in the array are mutable.
- [ ] The 0th element is immutable and cannot be modified. All other elements can be modified.
- [ ] Yes, val does not make arrays immutable.
- [x] Yes, val does not make arrays immutable.
- [ ] No, val makes the array and values of the array immutable.


Expand All @@ -171,18 +172,54 @@ def main () {
```
- [ ] 1,2,3,4,5
- [ ] 0,1,2,3,4
- [ ] 1,2,3,4
- [x] 1,2,3,4
- [ ] 2,3,4,5


#### Q20. What do you call objects with immutable state?

- [ ] singletons
- [x] singletons
- [ ] stationary objects
- [ ] functional objects
- [ ] fixed objects


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

- [x] use array named args
- [ ] use tuple named args
- [ ] use numbered variables with a _ prefix for example _ 1, _ 2, _ 3
- [ ] use numbered variables with a $ prefix - for example $1, $2, $3


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

- [ ] 4
- [x] an error
- [ ] 6
- [ ] 3


#### Q23. Which statement returns a success or a failure indicator when you execute this code?
val MyFuture = Future {runBackgroundFunction() }

- [x] myFuture.onComplete
- [ ] myFuture(status)
- [ ] myFuture.Finished
- [ ] complete(myFuture)


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

- [ ] %
- [ ] &
- [ ] _
- [x] *


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

- [ ] polyinheritance
- [ ] multilevel inheritance
- [ ] multimode inheritance
- [x] hierarchical inheritance

0 comments on commit b69d046

Please sign in to comment.