Tuesday, December 15, 2015

Scala test answers of 2016.

In this post you can find Complete and recently updated Correct Question and answers of Scala. All Answers updated regularly with new questions. Upwork Scala test answers of 2016.



Question:* When importing all the names of a package or class, which character do you use instead of " * "?

Answer: • "_"

Question:* Describe class AnyRef

Answer: • All types except the value types descend from AnyRef

Question:* What is a lazy var?

Answer: • `lazy var` is not supported by Scala

Question:* In the expression: List(1,2,3).foldLeft(x){case (a,b) => a+b} `x` is:

Answer: • The "accumulator," which is the initial value for `a`

Question:* In the expression: List(1,2,3) reduceLeft ( (a,b) => a+b ) `b` refers to:

Answer: • The next element in the list

Question:* Witch one of the following operators is use for sequencing Parsers

Answer: • ~

Question:* True or False? Methods taking one argument can be used with infix syntax?

Answer: • True

Question:* What is an expression following the "if" keyword?

Answer: • A guard

Question:* What is a higher-order function?

Answer: • Higher-order functions are functions that take other functions as parameters.

Question:* Explain how "abc".length returns 3

Answer: • An implicit conversion converts the java.lang.String into a scala.collection.immutable.StringOps, which supports a length method.

Question:* What is the value of the following expression? { val a = List(1,2,3) val b = List(4,5,6) (a,b).zipped.map(_+_) }

Answer: • List(5,7,9)

Question:* Which statement best describes an Iterator

Answer: • An Iterator is a stream of incoming items where advancing to the next item consumes the current item

Question:* Which of the following is a pattern matching any value, without giving it a name, represented by " _ "?

Answer: • A placeholder

Question:* True or False? Scala compiler will never require you to specify the result type of a function.

Answer: • False

Question:* It is possible to override methods inherited from a _____ in Scala.

Answer: • Super-class

Question:* What is the largest Tuple that Scala supports?

Answer: • 22

Question:* Which statement is true about sealed classes.

Answer: • A sealed class may not be directly inherited, except if it is defined in the same source file.

Question:* Classes in Scala, in contrast to Java, can have ______.

Answer: • Parameters

Question:* Which statement best describes a partial function?

Answer: • When applying the function, you do not pass in arguments for all of the parameters defined by the function, but only for some of them, leaving the remaining ones blank

Question:* What is the tool "schema2src" used for?

Answer: • Data-binding

Question:* Which statement about case classes is false?

Answer: • Case classes as sealed and therefor cannot be extended

Question:* True or False? Multiple classes can be imported from the same package by enclosing them in curly braces {}.

Answer: • True

Question:* Scala supports which types of polymorphism?

Answer: • Subtype, ad-hoc and parametric polymorphism

Question:* The following code will > var x=100; var y=200; x->y

Answer: • a Tuple with Arity 2

Question:* Does Scala support tail-call recursion?

Answer: • Partly at the compiler level. The compiler will try and unwind the recursive call into a loop.

Question:* What is the defaut parameter call semantics?

Answer: • By Value

Question:* What is the result type of the following expression? List(1, 2, true, false)

Answer: • List[AnyVal]

Question:* What would be the result of: Option[String]("hi") match { case None=> "hello!" }

Answer: • A MatchError would be thrown.

Question:* True or False? Like pre 1.5 Java, Scala suffers from lack of genericity.

Answer: • False

Question:* If you are defining scala classes in a 'package examplepackage', and want to ensure that a function 'foo' is only accessible by classes defined in the same package, how would you declare that function?

Answer: • private[examplepackage] def foo = {...}

Question:* `Nil` is generally the same as:

Answer: • List()

Question:* In Scala, type parameters and abstract types may be constrained by a _____.

Answer: • Type bound

Question:* True or False? Scala provides static members (members or fields).

Answer: • False

Question:* Scala is:

Answer: • An object-functional language that supports functional programming constructs

Question:* Which statement about pattern matching is true?

Answer: • The case set must be exhaustive

Question:* Does Scala support the return keyword?

Answer: • Yes, but it is not idiomatic Scala and therefor discouraged.

Question:* When a class inherits from a trait, it inherits all the code contained in the trait and implements the trait's:

Answer: • Interface

Question:* Everything, including numbers and functions, are _______ in Scala.

Answer: • Objects

Question:* What is a class with a single instance?

Answer: • A singleton object

Question:* Which of the following best describes Scala?

Answer: • All of these choices describe Scala

Question:* Scala's "Unit" roughly corresponds to which Java type?

Answer: • "void"

Question:* Which statement about List is false?

Answer: • List is a proxy for java.util.ArrayList

Question:* A valid description of a covariant type parameter would be:

Answer: • A type parameter which is allowed to vary down as the class is subtyped.

Question:* How would you define the method: def +(a:Int):Int in a Java interface that will be overriden or used in Scala code?

Answer: • public int $plus(int a)

Question:* When no super-class is specified, ______ is implicitly used.

Answer: • scala.AnyRef

Question:* True or False? In the Interpreter, you can define a new val with a name that was already used before.

Answer: • True

Question:* What is the name of the Scala compiler?

Answer: • "scalac"

Question:* `() => Unit` is best described as

Answer: • A procedure type definition

Question:* What would be returned by the following function: def foo(l:List[Int]) = { var x=l.head; l.collect{ case a:Int if a>x => x=a; a }; x } When passed: List(2,4,6,8,6,3,1)

Answer: • 8

Question:* What will the following function return: def foo(o:Any) = { o match { case Option(x) => "hi!" case anything => anything } } When passed a 'None' object?

Answer: • It won't compile

Question:* What is the data type of myVariable in the following: val myVariable = if (true) "Hello"

Answer: • Any

Question:* Are parenthesis `(` and curly braces `{` interchangeable?

Answer: • Only if the method expects a single parameter.

Question:* Which of these are NOT ways in which case classes differ from standard classes?

Answer: • Default definitions for the methods "equals" and "hashCode" are not provided

Question:* How would you get a List that was the result of appending `5:Int` to a `List(1,2,3)`. The order of the elements in the resulting List is irrelevant.

Answer: • List(1,2,3) :+ 5

Question:* Which statement about the Option[+A] class is false?

Answer: • scala.Nothing is derived from Option[+A]

Question:* Which predicate tests whether x is object identical to y?

Answer: • x eq y

Question:* Which of the following descriptions of case classes is *NOT* correct:

Answer: • Case classes are always immutable.

Question:* What is the Scala development environment designed for use in schools?

Answer: • Kojo

Question:* "Option" is:

Answer: • an abstract class

Question:* def g(): Int = try { 1 } finally { 2 } Calling g() results in

Answer: • 1

Question:* Which of the following is not one of the ways to increment the value of a variable i of type Int by 1.

Answer: • i++

Question:* Is it possible in Scala to declare a variable of type `Int` with a value of `null`?

Answer: • No

Question:* What is the runtime class of Unit?

Answer: • Class[Unit]

Question:* A function which associates a value to a (variable) name is known as a(n):

Answer: • Environment

Question:* def f(): Int = try { return 1 } finally { return 2 } Calling f() results in

Answer: • 2

Question:* True or False? Scala compiler automatically infers function parameter types.

Answer: • False



No comments:

HTML5 Upwork (oDesk) TEST ANSWERS 2022

HTML5 Upwork (oDesk) TEST ANSWERS 2022 Question: Which of the following is the best method to detect HTML5 Canvas support in web br...

Disqus for upwork test answers