nerdexam
Oracle

1Z0-808 · Question #43

1Z0-808 Question #43: Real Exam Question with Answer & Explanation

Sign in or unlock 1Z0-808 to reveal the answer and full explanation for question #43. The question stem and answer options stay visible for context.

Handling Exceptions

Question

Given the code fragment:
1. class X {
2. public void printFileContent () {
3. /* code goes here */
4. throw new IOException();
5. }
6. }
7. public class Test {
8. public static void main(String[] args) {
9. X xobj = new X();
10. xobj.printFileContent ();
11. }
12. }
Which two modifications should you make so that the code compiles successfully?

Options

  • AReplace line 8 with public static void main(String[] args) throws Exception
  • BReplace line 10 with:
    try {
     xobj.printFileContent();
    } catch (Exception e) {
    }
    catch (IOException e) {
    }
    
  • CReplace line 2 with public void printFileContent () throws IOException
  • DReplace line 4 with throw IOException("Exception raised")
  • EAt line 11, insert throw new IOException();

Unlock 1Z0-808 to see the answer

You've previewed enough free 1Z0-808 questions. Unlock 1Z0-808 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.

Topics

#Checked Exceptions#throws Declaration#Exception Propagation#Method Signatures
Full 1Z0-808 Practice