Scala

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

1.

One is a Java object, the other is a Scala object.

2.

clone() will copy class structures but not the data, while copy() will also copy data into new objects.

3.

There is no difference.

4.

copy() allows you to change values during the copying process; clone() does not.

Q 1 / 52

Scala

What value does this code return?

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

1.

a

2.

2

3.

b

4.

1

Q 2 / 52

Scala

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

1.

monads

2.

literal functions

3.

partially applied functions

4.

parallel collections

Q 3 / 52

Scala

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

1.

ArgumentExceptions

2.

AssertionException

3.

DiagrammedAssertions

4.

JUnit

Q 4 / 52

Scala

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

1.

Array

2.

ImmutableCollection

3.

List

4.

Tuple

Q 5 / 52

Scala

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

myfnc: ()Unit

1.

The function has no side effects.

2.

The function takes no parameters.

3.

The function returns no value.

4.

Returning unit types to the function is a closures.

Q 6 / 52

Scala

What type of number is 1234.e5?

1.

hexadecimal

2.

short

3.

floating point

4.

long

Q 7 / 52

Scala

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

1.

`List[(String, String)]`

2.

`List[(Array, Array)]`

3.

`List[(Collection, Collection)]`

4.

`List`

Q 8 / 52

Scala

What type of object does this code create?

val x = (1234, "Active")

1.

List

2.

Map

3.

Tuple

4.

Array

Q 9 / 52

Scala

Which is a subclass of all classes?

1.

AnyVal

2.

AnyRef

3.

Method

4.

Null

Q 10 / 52

Scala

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 scala val a = Array(1, 2, 3, 4, 5) for { e <- a if e > 2 } yield e

1.

Yes and no. It is different depending on the for construct and what it does.

2.

Yes, because the for section does not expose its scope.

3.

No, because for-yield shares the same scope, even though they are within separate curly braces.

4.

Yes, because they are within different curly braces.

Q 11 / 52

Scala

What is one way to implement pattern matching on methods?

Note: ambiguous question, it's not clear what kind of [pattern matching](https://docs.scala-lang.org/tour/pattern-matching.html) is meant here.

1.

using regex

2.

using monads

3.

using string matching

4.

using case classes

Q 12 / 52

Scala

What is the value of z after executing this code?

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

1.

List(a,b,c)

2.

List(List(a, b), c)

3.

List(c,a,b)

4.

List(c,List(a,b))

Q 13 / 52

Scala

What term is used to specify a precondition?

1.

assert

2.

require

3.

precondition

4.

mustHave

Q 14 / 52

Scala

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

1.

`scala.util.ExceptionHandling`

2.

`scala.Catch.Throw`

3.

`scala.exception.TryFinally`

4.

`scala.util.Try`

Q 15 / 52

Scala

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

val y = (math floor 3.1415 * 2)

1.

short

2.

double

3.

int

4.

bigInt

Q 16 / 52

Scala

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

1.

`%`

2.

`_`

3.

`^`

4.

`-`

Q 17 / 52

Scala

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

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

1.

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.

2.

The 0th element is immutable and cannot be modified. All other elements can be modified.

3.

Yes, val does not make arrays immutable.

4.

No, val makes the array and values of the array immutable.

Q 18 / 52

Scala

What is the output of this function?

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

1.

1,2,3,4,5

2.

0,1,2,3,4

3.

1,2,3,4

4.

2,3,4,5

Q 19 / 52

Scala

What do you call objects with immutable state?

**Note:** singletons may have mutable state

1.

singletons

2.

stationary objects

3.

functional objects

4.

fixed objects

Q 20 / 52

Scala

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

1.

use array named args

2.

use tuple named args

3.

use numbered variables with a _ prefix for example _ 1, _ 2, _ 3

4.

use numbered variables with a $ prefix - for example $1, $2, $3

Q 21 / 52

Scala

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

1.

4

2.

an error

3.

6

4.

3

Q 22 / 52

Scala

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

`val MyFuture = Future {runBackgroundFunction() }`

1.

myFuture.onComplete

2.

myFuture(status)

3.

myFuture.Finished

4.

complete(myFuture)

Q 23 / 52

Scala

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

1.

`%`

2.

`&`

3.

`_`

4.

`-`

Q 24 / 52

Scala

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

1.

polyinheritance

2.

multilevel inheritance

3.

multimode inheritance

4.

hierarchical inheritance

Q 25 / 52

Scala

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

1.

packages

2.

polymorphisms

3.

assertions

4.

traits

Q 26 / 52

Scala

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

1.

If the first else-if does not succeed, then no other else-ifs are tested.

2.

If an else-if does not succeed, then none of the remaining else-if statements or elses will be tested.

3.

All else-if statements are tested in all cases.

4.

If an else-if succeeds, then none of the remaining else-if statements or elses will tested.

Q 27 / 52

Scala

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

1.

recursive methods

2.

currying methods

3.

redefining methods

4.

overriding methods

Q 28 / 52

Scala

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

1.

`_`

2.

`*`

3.

`%`

4.

`&`

Q 29 / 52

Scala

What is the code below equivalent to?

scala myClass.foreach(println _)

1.

`myClass.foreach(println ())`

2.

`myClass.foreach(print NIL)`

3.

`myClass.loop(println ())`

4.

`myClass.foreach(x => println(x))`

Q 30 / 52

Scala

What is an advantage of an immutable object?

1.

Immutable objects use less memory than their mutable counterparts.

2.

Immutable objects do not require error handling.

3.

Immutable objects can be used in classes, mutable objects cannot.

4.

Immutable objects are threadsafe.

Q 31 / 52

Scala

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

1.

do-while loop

2.

while loop

3.

for loop

4.

do-until loop

Q 32 / 52

Scala

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?

1.

database driver

2.

connection

3.

prepared statement

4.

SQL view

Q 33 / 52

Scala

Which is _not_ a member of the collections hierarchy?

1.

Set

2.

Seq

3.

Hash

4.

Map

Q 34 / 52

Scala

Which term makes the contents of packages available without prefixing?

1.

use

2.

include

3.

import

4.

assertion

Q 35 / 52

Scala

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

1.

%

2.

DIV

3.

//

4.

/

Q 36 / 52

Scala

What are defined inside a class definition?

1.

method

2.

fields and methods

3.

fields, methods, and packages

4.

fields

Q 37 / 52

Scala

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

1.

singleton

2.

assertion

3.

trait

4.

monad

Q 38 / 52

Scala

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

1.

when the function has no side effects

2.

when the function returns a Unit type

3.

when the function is recursive

4.

when the function has side effects

Q 39 / 52

Scala

Why would you make a field private?

1.

so only methods in the same file can access the field

2.

so only methods in the same package can access the field

3.

so only methods in the same class could access the field

4.

so only methods defined in a Java class can access the field

Q 40 / 52

Scala

What's the difference between `.equals` and `==`?

1.

They do the exact same thing

2.

`==` won't work on objects

3.

`==` cannot be applied to `String`

4.

`==` is a wrapper of `.equals()` and checks for nulls

Q 41 / 52

Scala

What is denotes the intersection between two sets?

1.

||

2.

&&

3.

&

4.

%

Q 42 / 52

Scala

What's the best way to execute code in the background in a separate thread?

1.

AltFuture

2.

Future

3.

AltProcess

4.

AltThread

Q 43 / 52

Scala

What do you call a function defined in a block?

1.

private function

2.

block function

3.

local function

4.

method

Q 44 / 52

Scala

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

1.

multimode method

2.

polymorphic method

3.

closure

4.

collection method

Q 45 / 52

Scala

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

1.

IllegalArgumentException

2.

NumberFormatException

3.

NullPointerExcepetion

4.

MalformedParameterException

Q 46 / 52

Scala

In scala what is precondition?

1.

a constraint on where a method may be called from

2.

a constraint on values passed to a methode constructor

3.

a class of predifined error messages

4.

a class of Boolean operators

Q 47 / 52

Scala

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

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

1.

Change **list.map** to **list.par.map.**

2.

Change **toList** to **toListPar**

3.

Change **val** to **val.par**

4.

Change **toList** to **toParallelList**

Q 48 / 52

Scala

What is a free variable?

1.

a variable defined outside a function

2.

a variable referenced in a function that is not assigned a value by that function

3.

a variable that has a global scope

4.

a variable defined in a class and available to all methods in that class

Q 49 / 52

Scala

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

1.

**==** is wrapper of **.equals()** and checks for Nulls

2.

They do the exact same thing.

3.

== cannot be applied to String.

4.

== won't work on objects

Q 50 / 52

Scala

What's the best way to execute code in the background in a separate thread?

1.

AltThread

2.

AltFuture

3.

AltProcess

4.

Future

Q 51 / 52

Scala

undefined

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

1.

(1,2,4)

2.

1

3.

Nil

4.

2

Q 52 / 52