Scala(Engineering > Computer Science And Engineering ) Questions and Answers

Question 1. How should we end a stream to calculate sum of elements?
  1.    Sink.sum_
  2.    Sink.fold[Int, Int](0)(_ + _)
  3.    Sink.sum[Int](_)
  4.    Sink.map(_ + _)
Explanation:-
Answer: Option B. -> Sink.fold[Int, Int](0)(_ + _)





Question 2. Programming language which uses both object-oriented programming and functional programming paradigms is
  1.    Scala
  2.    Ada
  3.    Pascal
  4.    Machine language
Explanation:-
Answer: Option A. -> Scala





Question 3. What are the Scala variables?
  1.    var myVar : Int=0;
  2.    val myVal: Int=1;
  3.    Both A and B
  4.    None
Explanation:-
Answer: Option C. -> Both A and B





Question 4. When can you use traits?
  1.    If the behaviour will not be reused, then make it a concrete class. Anyhow it is not a reusable behaviour
  2.    In order to inherit from it in Java code, an abstract class can be used
  3.    If efficiency is a priority then lean towards using a class
  4.    All of the above
Explanation:-
Answer: Option D. -> All of the above





Question 5. What is the advantage of Scala?
  1.    Less error prone functional style
  2.    High maintainability and productivity
  3.    High scalability
  4.    All of these
Explanation:-
Answer: Option D. -> All of these





Question 6. Scala is a short form of
  1.    Scalable language
  2.    Sequential language
  3.    Script language
  4.    Scalar language
Explanation:-
Answer: Option A. -> Scalable language





Question 7. What are the few collections in Scala?
  1.    Array
  2.    List
  3.    Sets
  4.    All of these
Explanation:-
Answer: Option D. -> All of these





Question 8. What are three main part of akka streams?
  1.    Source, Flow, Sink
  2.    Source, Flow, BidirectionalFlow
  3.    ReactiveStream, Source, Flow
  4.    Stream, Source, Reactive
Explanation:-
Answer: Option D. -> Stream, Source, Reactive





Question 9. A FUNCTOR must have?
  1.    map function
  2.    flatMap function
  3.    map and flatMap both
  4.    None of the above
Explanation:-
Answer: Option B. -> flatMap function





Question 10. One of the following is an erroneous function definition, can you spot it
  1.    def functionName(x:Int,y:Int):Int=x+y
  2.    def functionName(x:Int,y:Int):Int={return x+y}
  3.    def functionName(x:Int,y:Int):Int{x+y} ()
  4.    def functionName(x:Int,y:Int)={x+y}
Explanation:-
Answer: Option D. -> def functionName(x:Int,y:Int)={x+y}