Embercode
✕
The STLQuick quiz

Immutable and generics

7 questions. Covers Generics and erasure.

Questions 1 to 5 of 7

  1. 1. What happens when this program runs? ``java import java.util.Map; public class Main { public static void main(String[] args) { Map<String, Integer> m = Map.of("a", 1, "a", 2); System.out.println(m); } } ``
  2. 2. Why does o instanceof List<String> fail to compile in Java, when o is declared as Object?
  3. 3. True or False: After Collections.unmodifiableList(backing) is made, adding an item to backing makes that new item visible through the view.
  4. 4. True or False: In C++, larger<int> and larger<double> are two separate functions in the compiled program, so each one has its own static variable.
  5. 5. What is wrong with this program? ``cpp #include <iostream> #include <map> #include <string> int main() { const std::map<std::string, int> stock{{"pen", 2}}; int n = stock["pin"]; std::cout << n << '\n'; } ``

5 question(s) left on this page.