What is the result, if the file myfile.txt does not exist?

Given the code fragment:

What is the result, if the file myfile.txt does not exist?

Given the code fragment:

What is the result, if the file myfile.txt does not exist?

A.
A runtime exception is thrown at line 4

B.
A runtime exception is thrown at line 7

C.
Creates a new file and prints no output

D.
Compilation fails

Explanation:

!! Compilation fails if FileNotFoundException is tried to catch (Line 12)
(The exception FileNotFoundException is already caught by the alternative IOException)
———————————————————————————————–if this is removed will be thrown a FileNotFoundException at line 4.



Leave a Reply 2

Your email address will not be published. Required fields are marked *


karim Ali

karim Ali

A

Babak

Babak

A is correct if we solve compile error on catch.
Answer is D.