• 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 containing an abstract method.

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot!
That was really helpful.

Teju
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic