Leave a Reply 3

Your email address will not be published. Required fields are marked *


kevin

kevin

The correct answer should be (C) option B.

Roger

Roger

public class ExceptionTest{
public static void main(String[] args) {
try {
doSomething();
}
catch (SpecialException e) {
System.out.println(e);
}
}
static void doSomething()
{
int[] ages = new int[4];
ages[4] = 17;
doSomethingElse();
}
static void doSomethingElse()
{
throw new SpecialException(“Thrown at end of doSomething() method”);
}
}
class SpecialException extends RuntimeException
{
public SpecialException(String string)
{
super(string);
System.out.println(string);
}
}
> Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 4
at exceptions.ExceptionTest.doSomething(ExceptionTest.java:13)
at exceptions.ExceptionTest.main(ExceptionTest.java:4)

answer D, Option C is correct