Scala MCQ questions
Take a short practice test with instant feedback, then revise every question with its answer and the reason behind it.
- Questions
- 34
- From lessons
- 24
- Your last test
- —
Practice test
How many traits can a class mix in?
All questions with answers
Which keyword declares an immutable value?
Show answer
Answer: B. val
val cannot be reassigned.
What does List(1, 2, 3).map(_ * 2) return?
Show answer
Answer: B. List(2, 4, 6)
map applies the function to each element.
Which represents a missing value safely?
Show answer
Answer: B. None
None is the empty Option.
Which feature generates copy, equals and toString automatically?
Show answer
Answer: C. case class
Case classes are data classes.
What is a singleton in Scala written as?
Show answer
Answer: B. object
object defines a single instance.
What does s"Hello, $name" do?
Show answer
Answer: B. String interpolation
The s interpolator inserts values.
Which build tool is standard for Scala projects?
Show answer
Answer: B. sbt
sbt (and scala-cli for scripts).
Either is right-biased. What does Left usually represent?
Show answer
Answer: B. An error
Left carries the error, Right the success.
Which keyword introduces an extension method in Scala 3?
Show answer
Answer: B. extension
extension (x: T) def ... adds methods to T.
What does foldLeft(0)(_ + _) compute on List(1, 2, 3)?
Show answer
Answer: C. 6
It sums the list starting from 0.
Which platform does Scala mainly run on?
Show answer
Answer: B. The JVM
Scala compiles to JVM bytecode (Scala.js and Native exist too).
From the lesson: Introduction to ScalaWhich command installs Scala, sbt and scala-cli?
Show answer
Answer: B. cs setup
Coursier’s setup installs the whole toolchain.
From the lesson: Installing Scala and sbtWhat happens when you reassign a val?
Show answer
Which type means “no useful value”, like void?
Show answer
What does 1 until 5 contain?
Show answer
What is the type of (x: Int) => x.toString?
Show answer
Which interpolator formats numbers and is type-checked?
Show answer
What does list :+ 5 do to the original list?
Show answer
Answer: B. Nothing — it returns a new list
Immutable collections never change.
From the lesson: CollectionsWhat happens if no case matches?
Show answer
Which method creates a modified copy of a case class?
Show answer
By convention, which side of Either holds the success value?
Show answer
A for-comprehension over Options returns None when…
Show answer
Answer: B. Any generator is None
The chain short-circuits on the first None.
From the lesson: For ComprehensionsWhat replaces Java’s static members in Scala?
Show answer
Answer: B. Singleton objects
Members of an object behave like statics.
From the lesson: Classes and ObjectsHow many traits can a class mix in?
Show answer
What does (f andThen g)(x) compute?
Show answer