Open In App

Java | Exception Handling | Question 2

Like Article
Like
Save Article
Save
Share
Report issue
Report




class Test extends Exception { }
   
class Main {
   public static void main(String args[]) { 
      try {
         throw new Test();
      }
      catch(Test t) {
         System.out.println("Got the Test Exception");
      }
      finally {
         System.out.println("Inside finally block ");
      }
  }
}


(A)

Got the Test Exception
Inside finally block 

(B)

Got the Test Exception

(C)

Inside finally block 

(D) Compiler Error


Answer: (A)

Explanation: In Java, the finally is always executed after the try-catch block. This block can be used to do the common cleanup work. There is no such block in C++.

Quiz of this Question


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads