March 17th, 2006

Logo

For Mr. Carlson

Me to collection agency: Your job is to collect money from me, not to be my financial counselor.
Collection agency: That's not very nice.
  • Current Mood
    amused amused
Logo

Java Pre-assessment

So, I'm taking an online course in Java because I've never programmed in it before. In the section on exceptions, the pretest has this question:
Select the code in which an ArrayIndexOutOfBoundsException occurs and is properly caught.
  1. try {
      int intArray = new int[5];
      arr[7] = 5;
      System.out.println(arr[7]);
    } finally {
      System.out.println("Finally Caught");
    } catch (ArrayIndexOutOfBoundsException e) {
      System.out.println("Caught");
    }
  2. try {
      int intArray = new int[5];
      arr[7] = 5;
      System.out.println(arr[7]);
    } catch (ArrayIndexOutOfBoundsException e) {
      System.out.println("Caught");
    } finally {
      System.out.println("Finally Caught");
    }
  3. int intArray = new int[5];
    arr[7] = 5;
    System.out.println(arr[7]);
     catch (ArrayIndexOutOfBoundsException e) {
      System.out.println("Caught");
    } finally {
      System.out.println("Finally Caught");
    }
  4. try {
      int intArray = new int[7];
      arr[5] = 5;
      System.out.println(arr[7]);
      System.out.println("Finally Caught");
    } catch (ArrayIndexOutOfBoundsException e) {
      System.out.println("Caught");
    }

Select the correct answer.

A
0(0.0%)
B
1(50.0%)
C
0(0.0%)
D
1(50.0%)

For those who aren't programmers, it's a trick question. I've highlighted in red the key to the trick.

Collapse )