• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Interface

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.


I thought that the answer was 3 but it said that the answer is 4.....Why ?

Thanks.
 
Greenhorn
Posts: 7
IntelliJ IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The words in the options 3) and 4) can throw people off (pun intended ). Based on the Interface definition we know that someMethod() will have to be implemented. However, that method doesn't necessarily have to throw an Exception, it could choose not to throw one. By declaring a method throws an Exception we are telling the Java compiler to be aware of the situation and if exception is indeed thrown then it needs to look for a suitable Exception handler for the type of Exception thrown.

Does this help?

Cheers,
TR.
reply
    Bookmark Topic Watch Topic
  • New Topic