Exceptions

Q1:
public class MyProgram 
{
    public static void throwit() 
    {
        throw new RuntimeException();
    }
    public static void main(String args[])
    {
        try 
        {
            System.out.println('Hello world ');
            throwit();
            System.out.println('Done with try block ');
        }
        finally 
        {
            System.out.println('Finally executing ');
        }
    }
}
which answer most closely indicates the behavior of the program?

A The program will not compile.

B The program will print Hello world, then will print that a RuntimeException has occurred, then will print Done with try block, and then will print Finally executing.

C
The program will print Hello world, then will print that a RuntimeException has occurred, and then will print Finally executing.

D The program will print Hello world, then will print Finally executing, then will print that a RuntimeException has occurred.

ANS:A - The program will not compile.

Once the program throws a RuntimeException (in the throwit() method) that is not caught, the finally block will be executed and the program will be terminated. If a method does not handle an exception, the finally block is executed before the exception is propagated.



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.