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.
A,C,E
java.io.FileNotFoundException extends java.io.IOException
Test.close() can throw fewer or narrower exceptions than SampleCloseable.close
in the exam e is not a vaild answr
Great delivery. Sound arguments. Keep up the great work.|