-
What is the output of this program?
public class ExceptionHandling_Example
{
public static void main(String args[])
{
try
{
int p = 1;
int q = 10 / p;
try
{
if (q == 1)
p = p / p - p;
if (p == 2)
{
int r[] = {1};
r[8] = 9;
}
}
catch (NullPointerException e)
{
System.out.println("*****");
}
}
finally
{
System.out.print("***");
}
}
}
-
- *****
- ***
- Compilation Error
- Runtime Error
- None of these
Correct Option: B
The inner try block does not have a catch which can tackle ArrayIndexOutOfBoundException hence finally is executed which prints ‘***’ the outer try block does have catch for NullPointerException exception but no such exception occurs in it hence its catch is never executed and only ‘***’ is printed.