Exceptions

Q1: 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(); 
    } 
}

A BCD

B BDE

C BDE

D BD

ANS:A - BD

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.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.