Which two modifications should you make so that the code compiles successfully?

Given the code fragment:

Which two modifications should you make so that the code compiles successfully?
A. Replace line 13 with:

B. Replace line 7 with throw IOException ("Exception raised");
C. Replace line 11 with public static void main(String[ ]) args) throws Exception {
D. At line 14, insert throw new IOException ();
E. Replace line 5 with public void printFileContent () throws IOException {

Download Printable PDF. VALID exam to help you PASS.

4 thoughts on “Which two modifications should you make so that the code compiles successfully?

  1. with C,E code will be compiled , but also need to add “import java.io.*;”
    # javac Test12.java

  2. Answer C, E:
    When we say “throw new IOException” it means we are throwing a checked exception. Accordingly, the method that contains that line should either handle (by try/catch block) or declare the exception (by adding “throws IOException”) in the method signature. This also applies to the caller of the method as well. Therefore, we need to do that in both the printFileContent() method, as well as in the main() method, which is the caller of the printFileContent() method.

Leave a Reply

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