Quiz 09-16: Exceptions and Interfaces

Exceptions and Interfaces Quiz

Quiz Figures
public class MultipleCatchExample {
    public static void main(String[] args) {
        try {
            int a = 10, b = 0;
            int[] array = {1, 2, 3};

            int result = a / b; // Divides by zero

            // Out of bounds array access on next line
            System.out.println("Array element: " + array[5]);

        } catch (ArithmeticException ae) {
            System.out.println("Cannot divide by zero.");
        } catch (ArrayIndexOutOfBoundsException aioobe) {
            System.out.println("Invalid array index.");
        } // try

        System.out.println("Got to the end!");
    } // main
} // MultipleCatchExample

hide circle
hide empty members
set namespaceSeparator none
skinparam classAttributeIconSize 0
skinparam classAttributeIconSize 0
skinparam genericDisplay old
skinparam defaultFontName monospaced
skinparam class {
    BackgroundColor LightYellow
    BackgroundColor<<interface>> AliceBlue
}

interface Hittable <<interface>> {
  {abstract} + takeDamage(damage: double): void
  {abstract} + defend(): void
}

class Hero implements Hittable {
  + swingSword(): void
  + <<override>> takeDamage(damage: double): void
  + <<override>> defend(): void
}

class Monster implements Hittable {
  + summonBackup(): void
  + <<override>> takeDamage(damage: double): void
  + <<override>> defend(): void
}