Which three implementations are valid?

Given the code fragment:
interface SampleClosable {
public void close () throws java.io.IOException;
}
Which three implementations are valid?

Given the code fragment:
interface SampleClosable {
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 implements SampleCloseable {
public void close() throws java.io.FileNotFoundException {
/ / do something
}
}

D.
public class Test extends SampleCloseable {
public void close() throws java.IO.IOException {
/ / do something
}
}

E.
public class Test implements SampleCloseable {
public void close()
/ / do something
}
}

Explanation:
A: Throwing the same exception is fine.
C: Using a subclass of java.io.IOException (here java.io.FileNotFoundException) is fine
E: Not using a throw clause is fine.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


drmorriarti

drmorriarti

A,C,E
java.io.FileNotFoundException extends java.io.IOException
Test.close() can throw fewer or narrower exceptions than SampleCloseable.close

ciscozel

ciscozel

in the exam e is not a vaild answr

special info

special info

Great delivery. Sound arguments. Keep up the great work.|