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

4 Responses

  1. mahesh chand says:

    First question: var band={
    var name=”sublime”
    name
    }

    It won’t raise an error. It will return sublime.

    • DataFlair Team says:

      Hi Mahesh,
      Try copying the code and running it the way it is. It will give you the error “not found: value name”. name is out of scope outside the variable band.
      Hope, it helps. Please refer our sidebar, for more Scala Quizzes.

  2. Patrick says:

    Q6 and Q7 I cannot see how the answers to these are both valid? Could you confirm they are correct please.Maybe question needs rewording.They are very similar code samples yet have differing correct answers?Thanks

    • DataFlair Team says:

      Hey Patrick,
      Thanks for pointing that out. There are some technical issues with Q.6 and Q.7. Our technical team has reviewed it and made the necessary changes.
      Now, you can enjoy your learning hurdle-free.

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.