• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

simple question about overriding  RSS feed

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exception can an overridden method throw in comparison with the method it is overriding?
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The over ridden method can throw same exception as super class method throwing & the subclasses of that exception.
But it can not throw peer class of that exception & superclass of that exception. Eg.

This code will work because overridden method is throwing same & subclass of that exception
 
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You understand what overriding is right? If not, overriding allows a subclass to re-define a method it inherits from it's superclass
* overriding methods:
* appear in subclasses
* have the same name as a superclass method
* have the same parameter list as a superclass method
* have the same return type as as a superclass method
* the access modifier for the overriding method may not be more restrictive than the access modifier of the superclass method
- if the superclass method is public, the overriding method must be public
- if the superclass method is protected, the overriding method may be protected or public
- if the superclass method is package, the overriding method may be packagage, protected, or public
- if the superclass methods is private, it is not inherited and overriding is not an issue
* the throws clause of the overriding method may only include exceptions that can be thrown by the superclass method, including it's subclasses

As for exceptions example:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!