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 CSebbene non sia chiaro cosa ci sia scritto nel punto C, sicuramente la D è errata perchè una classe non può estendere un'interfaccia.
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.
RispondiEliminaExam 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