Java OCA OCP Practice Question 2561

Question

Consider the following code snippet and choose the best option:

public static void main(String []files) {
        try (FileReader inputFile =
                new FileReader(new File(files[0]))) { // #1
        }
        catch (FileNotFoundException | IOException e) { // #2
                e.printStackTrace();
        }
}
  • a) The code snippet will compile without any errors.
  • b) The compiler will report an error at statement #1.
  • c) The compiler will report an error at statement #2.
  • d) The compiler will report errors at statements #1 and #2.


c)

Note

Both of the specified exceptions belong to same hierarchy (FileNotFoundException derives from an IOException), so you cannot specify both exceptions together in the multi-catch handler block.




PreviousNext

Related