What is wrong with the following code written in a single file named Main.java?
class Exception1 extends Throwable { } class Exception2 extends Exception1 { } public class Main{ public static void main (String args []) throws Exception1{ try{ /* ww w .j a v a 2 s .c o m*/ m1 (); }catch (Exception1 e){ throw e; }finally{ System .out.println ("Done"); } } public static void m1 () throws Exception2{ throw new Exception2 (); } }
Select 2 options
Correct Options are : D E
For Option A.
That's OK. You can put a Super class in the throws clause and then you can throw any subclass exception.
For Option B.
You sure can.
The only limitation is you can have only one top level public class in a file.
For Option C.
You can catch a subclass exception in the catch clause that catches a super class.
for Option E.
Done will be followed by an exception. Finally is always executed and Only exception is System .exit ();