nerdexam
Oracle

1Z0-803 · Question #1

Given: Which two actions, used independently, will permit this class to compile?

The correct answer is C. Adding throws IOException to the main() method signature and to the dosomething() method D. Adding throws IOException to the dosomething() method signature and changing the catch argument. The IOException must be caught or be declared to be thrown. We must add a throws exception to the doSomething () method signature (static void doSomething() throws IOException). Then we can either add the same throws IOException to the main method (public static void main(String[

Handling Exceptions

Question

Given:

Which two actions, used independently, will permit this class to compile?

Exhibit

1Z0-803 question #1 exhibit

Options

  • AAdding throws IOException to the main() method signature
  • BAdding throws IOException to the doSoomething() method signature
  • CAdding throws IOException to the main() method signature and to the dosomething() method
  • DAdding throws IOException to the dosomething() method signature and changing the catch argument
  • EAdding throws IOException to the main() method signature and changing the catch argument to

How the community answered

(44 responses)
  • A
    14% (6)
  • B
    2% (1)
  • C
    77% (34)
  • E
    7% (3)

Explanation

The IOException must be caught or be declared to be thrown. We must add a throws exception to the doSomething () method signature (static void doSomething() throws IOException). Then we can either add the same throws IOException to the main method (public static void main(String[] args) throws IOException), or change the catch statement in main to IOException.

Topics

#checked exceptions#exception handling#method signatures#throws keyword

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice