Java OCA OCP Practice Question 347

Question

Consider the following class hierarchy and code fragment:

 1. try { // w w w  .  j a va  2 s.  c om
 2.   // assume s is previously defined 
 3.   URL u = new URL(s); 
 4.   // in is an ObjectInputStream 
 5.   Object o = in.readObject(); 
 6.   System.out.println("Success"); 
 7. } 
 8. catch (MalformedURLException e) { 
 9.   System.out.println("Bad URL"); 
10. } 
11. catch (StreamCorruptedException e) { 
12.   System.out.println("Bad file contents"); 
13. } 
14. catch (Exception e) { 
15.   System.out.println("General exception"); 
16. } 
17. finally { 
18.   System.out.println("Doing finally part"); 
19. } 
20. System.out.println("Carrying on"); 

What lines are output if the methods at lines 3 and 5 complete successfully without throwing any exceptions? (Choose all that apply.)

  • A. Success
  • B. Bad URL
  • C. Bad file contents
  • D. General exception
  • E. Doing finally part
  • F. Carrying on


A, E, F.

Note

With no exceptions, the try block executes to completion.

The message Success from line 6 is printed and A is part of the correct answer.

No catch is executed, so B, C, and D are incorrect.

Control then passes to the finally block.

It results in the message at line 18 being output, so E is part of the correct answer.

Because no exception was thrown, execution continues after the finally block.

It results in the output of the message at line 20.

F is part of the correct answer.




PreviousNext

Related