giovedì 28 marzo 2013

Q76


Given the code fragment:

interface SampleCloseable {public void close () throws java.io.IOException;}

Which three implementations are valid?

A.
 public class Test implements SampleCloseable { public void close() throws java.io.IOException { //do something } } 

B.
 public class Test implements SampleCloseable { public void close () throws Exception { // do something } } 

 
C.
 public class Test implementations SampleCloseable { public void close () throws Exception { // do something } } 

 
D.
 public classTest extends SampleCloseable { public void close () throws java.IO.IOException { // do something } }
Risposta : A B e C
Sebbene non sia chiaro cosa ci sia scritto nel punto C, sicuramente la D è errata perchè una classe non può estendere un'interfaccia.

1 commento:

  1. Question is not complete. Option C is bad typed (implements instead implementations) and it FAILS because it's not permitted throw a more general exception on an interface's method implementation.

    Exam shows a F option which is correct (it´s permitted not to throw any exception):
    F. public classTest implements SampleCloseable { public void close() }

    So correct options are:
    A(same exception)
    B(Child exception),
    F(throws nothing) **Missing in above question

    RispondiElimina