Sail E0 Webinar
Question


What will be the output of the program?


public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (RuntimeException ex) /* Line 10 */
{
System.out.print("B");
}
catch (Exception ex1)
{
System.out.print("C");
}
finally
{
System.out.print("D");
}
System.out.print("E");
}
public static void badMethod()
{
throw new RuntimeException();
}
}
Options:
A .  BD
B .  BCD
C .  BDE
D .  BCDE
Answer: Option C

A Run time exception is thrown and caught in the catch statement on line 10. All the code 

after the finally statement is run because the exception has been caught.



Was this answer helpful ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers