Originally posted by Arun Pai:
Read the following code below.
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.
answer given is 4, How about 3??
-Arun
First off, we should know subclasses' overriding methods could only throw the same exception or narrow down parent's exception.
For this example, in my opinion, 3 is not right, because it states
public void someMethod() which has tothrow an exception which is a subclass of java.lang.Exception.
public void someMethod() throws IOException
public void someMethod() throws Exception
public void someMethod()
are all right.