This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
public interface AQuestion { public abstract void someMethod() throws Exception; } A Class implementing this interface should
1 Necessarily be an abstract class. 2 Should have the method public abstract void someMethod(); 3 Should have the method public void someMethod() which has to throw an exception which is a subclass of java.lang.Exception. 4 Should have the method public void someMethod() which need not throw an Exception.
The answer given is 4. But I am not really able to sink the concept behind this. Any inputs?? Thanks
Anthony Watson
Ranch Hand
Joined: Sep 25, 2003
Posts: 327
posted
0
1. Can't be this because a regular non abstract class can implement an interface
2. This would mean that the class does not provide an implementation of someMethod, which would not be illegal but it would cause the implementing class to have to be abstract.
3 & 4. Remember that a class can provide empty implementations of the methods of an interface. If you don't put any code at all in your class's implementation of someMethod, it doesn't make sense that you should have to declare that your implementation throws an Exception, because it never would. Java does not require that a method implementation throws any of the exceptions that are declared in an interface.