Java

JA+ I V8 for OCA-JP-I SE8 (1Z0-808)

Test 1

Q 1 of 14 QID: enthuware.ocajp.i.v8.2.827 Mark

What will be the output when the following program is run?

package exceptions;
public class TestClass{
    public static void main(String[] args) {
        try{
            hello();
        }
        catch(MyException me){
            System.out.println(me);
        }
    }
    
    static void hello() throws MyException{
        int[] dear = new int[7];
        dear[0] = 747;
        foo();
    }
    
    static void foo() throws MyException{
        throw new MyException("Exception from foo");
    }
}

class MyException extends Exception {
    public MyException(String msg){
        super(msg);
    }
}
(Assume that line numbers printed in the messages given below are correct.)

Please select 1 option

  • Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
        at exceptions.TestClass.doTest(TestClass.java:24)
        at exceptions.TestClass.main(TestClass.java:14)
  • Error in thread "main" java.lang.ArrayIndexOutOfBoundsException
  • exceptions.MyException: Exception from foo
  • exceptions.MyException: Exception from foo
        at exceptions.TestClass.foo(TestClass.java:29)
        at exceptions.TestClass.hello(TestClass.java:25)
        at exceptions.TestClass.main(TestClass.java:14)