wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
 
wood burning stoves
 
subject: Interface containing an abstract method.
 
Similar Threads
Exception - Abhilash Mock
Interface
Interface
tricky question
can anyone explain me this?