File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface containing an abstract method.

 
Tejaswini Shirkhedkar
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tejaswini Shirkhedkar
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot!
That was really helpful.

Teju
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic