NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content

Quiz: Scala

Scala questions from real interviews as a quiz, with an explanation for every option.

10 questionsAll topicsScala

Try it: 5 questions

Loading…

Sample questions

  1. Which statements about resolving collisions in hash tables are correct?

    • With open addressing, a collision leads to searching for another slot according to a probe sequence.
    • Resizing the table guarantees that no more collisions will occur.
    • After a hash selects a location, keys are generally compared for equality.
    • With chaining, multiple entries that map to the same index are stored in one bucket.
    • Equal keys may have different hashCode values if that improves distribution.
    Full answer
  2. Which statement correctly compares how Bitcoin and Ethereum account for funds?

    • Bitcoin uses accounts with balances, while Ethereum uses UTXOs.
    • Both networks use UTXOs, but Ethereum stores them in smart contracts.
    • Bitcoin uses UTXOs, while Ethereum uses accounts with balances and state.
    • Both networks store funds only as an address balance and differ only in transaction format.
    Full answer
  3. Which description of Future[A] in Scala is the most accurate?

    • It represents a lazy computation of type A that starts only when Await is called.
    • It represents an already computed value of type A, available without waiting or handling errors.
    • It represents the result of an asynchronous computation of type A, which may complete with a value or an error.
    • It represents a thread of execution that stores state and can be cancelled with cancel.
    Full answer
  4. What does a hash collision mean in a hash table?

    • Two different keys are considered equal when compared.
    • Different keys have the same hash code.
    • A key's hash code matches its index in the table.
    • Equal keys have different hash codes.
    Full answer
  5. How are transaction fees generally calculated in Bitcoin and Ethereum?

    • Bitcoin uses a fee rate per transaction size; Ethereum uses gas consumed and the effective gas price.
    • Bitcoin charges a percentage of the transfer amount; Ethereum charges a fixed amount per transaction.
    • Bitcoin charges by the number of inputs; Ethereum charges by the amount of ETH sent.
    • Bitcoin charges by confirmation time; Ethereum charges by transaction size in bytes.
    Full answer
  6. How does synchronous replication typically differ from asynchronous replication in write acknowledgements and failure outcomes?

    • With synchronous replication, a write waits for the required replicas to confirm it; this usually reduces the risk of losing acknowledged data but increases latency.
    • Both modes acknowledge writes in the same way; they differ only in how often replicas check the primary.
    • With asynchronous replication, a write waits for every replica to confirm it, improving durability at the cost of availability.
    • With synchronous replication, the primary acknowledges a write immediately and replicas receive it later, so latency is lower.
    Full answer
  7. What happens when this Scala code is compiled?

    class A
    class B extends A
    
    object Example extends App {
      def replace(values: Array[A]): Unit = {
        values(0) = new A
      }
    
      val values: Array[B] = Array(new B)
      replace(values)
      println(values)
    }
    
    • It compiles, but the write fails with ArrayStoreException.
    • It compiles and replaces the array element with an instance of A.
    • It does not compile: Array[B] cannot be passed as Array[A].
    • It compiles, and println outputs the unchanged array.
    Full answer
  8. Ten threads must each increment a shared counter once. Which approach guarantees that the final value is 10 after all threads have finished?

    • Use an AtomicInteger, start all threads, and immediately read get() without waiting for them to finish.
    • Use an AtomicInteger, call incrementAndGet() in each thread, then join() all threads and read get().
    • Use @volatile var counter = 0, run counter += 1, and join() all threads.
    • Use a regular var counter = 0, run counter += 1 in each thread, and join() all threads.
    Full answer
  9. How can synchronized be used in Java and Scala?

    • Only blocks with an explicit monitor can be synchronized; methods cannot be declared synchronized.
    • Only entire methods can be synchronized; individual code sections cannot be protected.
    • Java supports methods and arbitrary blocks; Scala uses a block synchronized on an AnyRef monitor.
    • Both methods and blocks can be synchronized, but the monitor is always chosen automatically.
    Full answer
  10. In the context of program correctness, what is an invariant?

    • A type that cannot be used with different type parameters
    • A condition that must remain true across valid operations
    • A value that cannot be changed after an object is created
    • A condition checked only when the program starts
    Full answer