Scala Quiz | 5 Min Challenge for Scala Programming
Scala course with real-time projects Start Now!!
This Scala Quiz will help you to boost your Scala knowledge and help to prepare for Scala interview.
DataFlair has published a series of Scala Quizzes from basic to advanced.
Before you start, please bookmark all quizzes and finish them before appearing for the next interview:
- Scala Quiz – 1
- Scala Quiz – 2
- Scala Quiz – 3
- Scala Quiz – 4
All The Best For Scala Quiz!!
We hope, you give all correct answers to this Scala Quiz. Have you enjoyed the Scala Quiz? Share your feedback with us!
Do not forget to share your score in the comments and challenge your friends to score more.
You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google
Q.17. How do you turn the string “batmanstein” to the string “Man”?
b. “batmanstein”.drop(3).take(3).capitalize
d. “batmanstein”.drop(3).capitalize.take(3)
b and d are correct
Hi Jefferson,
Thanks for the observation for Scala quiz. We already made the necessary changes.\
Keep exploring DataFlair
Both
Q.13. Select the statements that will successfully compile and run:
a. val msg:String = "Testing" println(msg+" a horse ");
b. var msg="Testing" println(msg+" a test")
c. var msg="Testing" println("msg is :"+(msg=msg+" " +msg)
d. All of the above
What will be output, Can you give me explanation..!
Hello Paresh,
Nice Catch!
Thanks for pointing out our typo mistake in this Scala Quiz. We make all the necessary changes. Now, all the statements will execute successfully.
Regards,
DataFlair
Q.19. What does the variable x hold in the following code:
var x,y,z=(1,2,3)
Correct answer should be 1
Which of the following statements are true about Lists and Arrays?
Lists are immutable
Arrays are mutable
Once you have declared a List, you cannot add more elements later
All of the above
List can add more element with the method ::
Not exactly, the result is a list, but it’s not the original list, but a different new one.
Hello Alejandro,
Thanks for playing the above Scala Quiz.
Here is the answer of your query, Scala Lists are immutable whereas arrays are mutable in Scala. For complete information you can refer our Scala list tutorial.
> We do not need to pass these parameters to a method when calling it:
Of course “Default parameters” is true! And it’s always true.
“Implicit parameters” is only true if and only if there are the right implicit values in scope!
Please correct this mistake.
> UNIT is a data type in Scala. It pertains to no meaningful information.
It’s called “Unit” not “UNIT”! Scala is case sensitive, remember? (Question 5)
> Consider the following statements about vals and vars. Select the ones that are true.
> Reassigning to a val throws an error
> Reassigning to a var doesn’t throw an error
“Throws an error” is very misleading. Throwing errors sounds like something that happens at runtime.
What in fact happens is that compilation fails (with an error).
> A closure is:
> A function whose return value depends on a variable declared outside it
That’s simply false!
The captured value doesn’t need to contribute to the return value. It can trigger side-effects without changing the closure return value. Or it can do simply nothing (dead code).
> What is a monad in Scala?
> An object that wraps another
That’s nonsense!
Just don’t ask about monads if you don’t know what they are and how they’re implemented in Scala.
Only after lifting a value into a monad it wraps the value. It’s not an wrapper as is.
> What is a type class in Scala?
> A trait with at least one type variable
No. That’s just a possible implementation of a type class. There are also other encodings!
(This even contradicts the other wrong question about monads as monads are implemented with type classes. Boy…)