What will be the output of following java program? Assume that File1.txt exists.
public static void main(String args)
FileReader fis=new FileReader("File1.txt");
FileWriter fos=new FileWriter("File1Output.txt");
catch (Exception e)
catch (IOException ioe)
- Output file will have same content as in input File1.txt.
- An exception will be raised during run time.
- Compilation fails.
- Nothing will be printed in output file.
Option C is correct, a compile time error will be thrown by the compiler because of the catch block ordering.
Since Exception is a super class of all exceptions, any exception raised during the flow of program will go to first catch block always, never in second block.
You can write multiple catch blocks in java but child exceptions must come first than parent exceptions. (Vice versa makes the compilation process fail.)
Also, note that sibling exceptions order in catch block does not matter.