InputStream in new FileInputStream try SystemoutprintA code

InputStream in = new FileInputStream(...); try {System.out.print(\"A\"); ...//code that could cause an exception System.out.print(\"B\");} catch (I0Exception e) {System.out.print(\"C\");} finally {in.close(); System.out.print(\"D\");} System.out.println(\"E\"); What will be the string print in output if the try blocks throws a FileNotFoundException exception? ACDE ABDE ABCDE ACD

Solution

Answer: ACDE

When file not found exception occurred then it will be caught by IOException catch block.

So after \"A\" print this exception has occurred so \"B\" will not print and catch block will execute \"C\" will print. after catch block finally will execute so it will print \"D\" and last statement \"E\" will print at the end.

So it will print ACDE.

 InputStream in = new FileInputStream(...); try {System.out.print(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site