Download Printable PDF. VALID exam to help you PASS.
One thought on “What will be the output?”
The correct answer should be C.
Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 4
at ExceptionTest.doSomething(ExceptionTest.java:18)
at ExceptionTest.main(ExceptionTest.java:11)
class SpecialException extends Exception{
public SpecialException(String message){
super(message);
System.out.println(message);
}
}
public class ExceptionTest{
public static void main(String[] args){
try{
doSomething();
}catch(SpecialException e){
System.out.println(e);
}
}
static void doSomething() throws SpecialException{
int[] ages = new int[4];
ages[4] = 17;
doSomethingElse();
}
static void doSomethingElse() throws SpecialException{
throw new SpecialException(“Thrown at end of doSomething mehtod”);
}
}
The correct answer should be C.
Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 4
at ExceptionTest.doSomething(ExceptionTest.java:18)
at ExceptionTest.main(ExceptionTest.java:11)
class SpecialException extends Exception{
public SpecialException(String message){
super(message);
System.out.println(message);
}
}
public class ExceptionTest{
public static void main(String[] args){
try{
doSomething();
}catch(SpecialException e){
System.out.println(e);
}
}
static void doSomething() throws SpecialException{
int[] ages = new int[4];
ages[4] = 17;
doSomethingElse();
}
static void doSomethingElse() throws SpecialException{
throw new SpecialException(“Thrown at end of doSomething mehtod”);
}
}