Scala Practice Test | Check Your Scala Knowledge

1. Scala Practice Test

Check your Scala knowledge by taking this Scala Practice Test. After completing the earlier parts of Scala Quiz, you are able to face tricky and interesting Scala Practice Test.

Before, we move towards Scala Practice Test let’s take a quick revision of Scala Programming Language.

Scala Practice Test | Check Your Scala Knowledge

Scala Practice Test | Check Your Scala Knowledge

Best of Luck!! For the Scala Practice Test.

Q.1. Select the correct output for the following code:
var band={
var name="sublime"
name
}
println(name)

Correct! Wrong!

Q.2. Choose the correct output for the following code:
val x:Option[String]=Some("hi")
println(x.get)

Correct! Wrong!

Q.3. The following code compiles:
class Complex(real:Double,imaginary:Double){
def re()=real
def im()=imaginary
}

Correct! Wrong!

Q.4. What does this code print?
var y:Option[String]=None
y.get

Correct! Wrong!

Q.5. Is the following function pure?
def change:Unit={
x=x+10
}

Correct! Wrong!

Q.6. Select the correct output for the following code:
object Flash{
def superpower="speed"
}

Correct! Wrong!

Q.7. Choose the correct output:
object Dog{
def bark=”woof”
}

Correct! Wrong!

Q.8. Select the correct output:
val numbers=List(11,22,33)
var total=0
for(i<-numbers){
total+=i
}
println(total)

Correct! Wrong!

Q.9. Decide what the following code prints:
val odds=List(3,5,7)
var result=1
odds.foreach((num:Int)=>result*=num)
println(result)

Correct! Wrong!

Q.10. Okay, now try to do this one:
val evens=List(2,4,8)
println{
evens.foldLeft(0) { (memo: Int, y: Int) =>
memo+y
}
}

Correct! Wrong!

Q.11. Select appropriate output:
def quadruple(x:Int):Int=x*4
val quadrupleCopy=quadruple _
println(quadrupleCopy(-1))

Correct! Wrong!

Q.12. Which abstraction from functional programming helps us deal with updating complex immutable nested objects?

Correct! Wrong!

Q.13. Choose the correct output:
var greeting:Option[String]= Some("hello")
greeting= Some(7)
println(greeting.get)

Correct! Wrong!

Q.14. We do not need to pass these parameters to a method when calling it:

Correct! Wrong!

Q.15. Select the correct output:
val cool=Map("a"->"aaa", "b"->"bbb", "a"->"ccc")
println(cool("a"))

Correct! Wrong!

So, this was all about Scala Practice Test. Hope you like our Scala Quiz Questions. Share your query, with us!

Play our last Scala Quiz that helps you to prepare for upcoming Scala Interviews

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.