Skip to content
KALANBLON
Show contents

Chapter 7 of 7 · 10 min

Quiz: objects and errors

Classes, records, encapsulation and exceptions: let's check that your objects protect their rules. You need 70% correct answers.

Quiz

6 questions · pass mark: 70%

  1. 1.Why declare the attribute balance as private?

    One answer

  2. 2.What does record Point(int x, int y) generate automatically?

    One answer

  3. 3.What does this code display?

    One answer

    try {
        IO.println("A");
        int x = 5 / 0;
        IO.println("B");
    } catch (ArithmeticException e) {
        IO.println("C");
    } finally {
        IO.println("D");
    }
  4. 4.Fill in the blank to signal that an argument is invalid.

    Complete the code

    if (age < 0) {
        ____ new IllegalArgumentException("negative age");
    }
  5. 5.Which practices are good with exceptions? (several answers)

    Several answers possible

  6. 6.What is @Override in front of public String toString() for?

    One answer

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