Given:
2. import java.io.*; 3. interface Printable { 4. String m() throws Exception; 5. Printable get(); //from w w w. j a v a 2s. c o m 6. void doInsane(); 7. } 8. class Shape implements Printable { 9. public String m() throws IOException { 10. throw new IOException(); 11. } 12. public Shape get() { return new Shape(); } 13. public void doInsane() throws NullPointerException { 14. throw new NullPointerException(); 15. } 16. }
What is the result? (Choose all that apply.)
m()
method will not compile.get()
method will not compile.doInsane()
method will not compile.A is correct, the code is all legal.
It's okay for an interface method to declare an exception.
It's okay for an implementing method to throw either a narrower exception or runtime exception.
Finally, it's okay for an implementing method to use a covariant return (as in line 12).