Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface containing an abstract method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interface containing an abstract method." Watch "Interface containing an abstract method." New topic
Author

Interface containing an abstract method.

Tejaswini Shirkhedkar
Greenhorn

Joined: Jun 22, 2004
Posts: 17
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
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.


Anthony W.<br />MCP, SCJP 1.4, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
Tejaswini Shirkhedkar
Greenhorn

Joined: Jun 22, 2004
Posts: 17
Thanks a lot!
That was really helpful.

Teju
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interface containing an abstract method.