What will be the output? Given: What will be the output? Given: What will be the output? A. Option A B. Option D C. Option B D. Option C Show Hint ← Previous question Next question →
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 Reply
The correct answer should be (C) option B.
d
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