Java OCA OCP Practice Question 1584

Question

What will be the output of the following program?

public class Main{
   public static void main (String [] args) throws Exception{
      try{//  ww w.  j  a  va2s  .c om
         m ();
         System.out.println ("try");
      }
      catch (Exception e){
         System.out.println ("catch");
      }
      finally    {
         System.out.println ("finally");
      }
      System.out.println ("out");
    }
   public static void m (){  }
}

Select 1 option

  • A. try finally
  • B. try finally out
  • C. try out
  • D. catch finally out
  • E. It will not compile because m () does not throw any exception.


Correct Option is  : B

Note

Since the method m () does not throw any exception, try is printed and the control goes to finally which prints finally.

After that out is printed.




PreviousNext

Related