Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

overriding method

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Every1,
This stmt is from java.sun.com/docs.
"The overriding method can have a different throws clause as long as it doesn't declare any types not declared by the throws clause in the overridden method".
I haven't understood the mean of the above stmt.Could anyone of you explain the above with example...
Thanks and Regards
Priya
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Priya..
I think I can explain this..
I beleive you recollect having read an overriding method can throw only those exceptions which are the subclasses of those Exceptions declared in the throws clause of the overridden method.
your statement means just that , it implies that the overriding method can have a different throws clause, however. see example.

[CODE]import java.io.*;
public class mymainclass
{
void method() throws IOException
{
}
}
class mysubclass
{
static void method() throws EOFException
{
}
} [CODE]

In the sub class, the throws clause is legal,because ,EOFException is a subclass of IOException,
Being more specific, you want the overriding method in your subclass handle only EOFException..
HTH,
Ramani.
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But do not forget all this is true only for checked exceptions
reply
    Bookmark Topic Watch Topic
  • New Topic