Skip to content
KALANBLON
Show contents

Chapter 3 of 7 · 10 min

Quiz: methods and collections

Methods, overloading, references, maps and sorting: let's check that you know how to organise your code and your data in Java. You need 70% correct answers.

Quiz

6 questions · pass mark: 70%

  1. 1.What does this program display?

    One answer

    void add(ArrayList<Integer> l) {
        l.add(4);
    }
    
    void main() {
        var l = new ArrayList<>(List.of(1, 2));
        add(l);
        IO.println(l);
    }
  2. 2.What does a method declared void show(String s) return?

    One answer

  3. 3.Which overloads can coexist with double price(double net)? (several answers)

    Several answers possible

  4. 4.Fill in the blank to read a value with 0 as the fallback if the key is missing.

    Complete the code

    int n = stock.____("flour", 0);
  5. 5.Which Map should you choose to go through the keys in alphabetical order?

    One answer

  6. 6.What does this code display?

    One answer

    var m = new TreeMap<String, Integer>();
    for (String s : List.of("b", "a", "b")) {
        m.merge(s, 1, Integer::sum);
    }
    IO.println(m);

Your progress is saved on this device. Create a free account to keep your progress on all your devices.