Practice Library
All MCQs
Browse exam-wise, subject-wise, and country-wise MCQs with explanations.
Choose an option to check your answer.
Correct Answer: A. A reusable abstraction containing method and field definitions
Explanation:
Classes can extend multiple traits.
Traits support interfaces and shared implementation.
Choose an option to check your answer.
Correct Answer: D. Collects the produced values into a result collection
Explanation:
Without yield, a for-comprehension is commonly used for side effects.
With yield, it transforms input elements into a new collection.
Choose an option to check your answer.
Correct Answer: C. Expressing iteration, filtering, and mapping over collections
Explanation:
For-comprehensions translate into methods such as map, flatMap, and withFilter.
They can produce values using yield.
Choose an option to check your answer.
Correct Answer: B. Embedding expressions directly inside a string
Explanation:
Expressions preceded by $ are evaluated and inserted.
This improves readability over repeated concatenation.
Choose an option to check your answer.
Correct Answer: A. With _1
Explanation:
Tuple components use positional accessors _1, _2, and so on.
Pattern matching can also destructure tuples.
Choose an option to check your answer.
Correct Answer: D. A fixed-size grouping of values that may have different types
Explanation:
Tuples provide lightweight product types such as (String, Int).
Pair RDDs commonly use Tuple2 values.
Choose an option to check your answer.
Correct Answer: C. A concise class with generated methods useful for immutable data modeling
Explanation:
Case classes automatically support pattern matching, equality, and copying.
They are commonly used to model records.
Choose an option to check your answer.
Correct Answer: B. Selecting behavior by comparing a value against structured cases
Explanation:
The match expression checks cases in order and can extract components.
It is more powerful than a simple switch statement.
Choose an option to check your answer.
Correct Answer: A. An Option with no value
Explanation:
None represents absence without using a raw null.
Pattern matching and combinators can handle it safely.
Choose an option to check your answer.
Correct Answer: D. An Option containing the value x
Explanation:
Some wraps an existing value in the Option type.
Code can safely distinguish it from None.
Choose an option to check your answer.
Correct Answer: C. A value that may be present or absent
Explanation:
Some(value) represents presence and None represents absence.
Option reduces direct reliance on null.
Choose an option to check your answer.
Correct Answer: B. A collection of key-value associations
Explanation:
Each key maps to a value within the collection.
Immutable Map is the default import in standard Scala.