my dog learned polymorphism*
The moose likes Beginning Java and the fly likes simple question about overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "simple question about overriding" Watch "simple question about overriding" New topic
Author

simple question about overriding

s.palanivel rajan
Ranch Hand

Joined: Sep 22, 2009
Posts: 40
What exception can an overridden method throw in comparison with the method it is overriding?


With Regards,
S.Palanivel Rajan B.E.
pankaj vijay
Ranch Hand

Joined: Apr 01, 2008
Posts: 75
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


Pankaj Vijay (SCJP, SCBCD)
Learn Core Java,Learn Servlet Jsp, SCJP Questions,Struts Tutorial
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2247
    
    7

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:


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple question about overriding
 
Similar Threads
How to convert xml to pdf form in java
how to start before the main starts
Finding formula?
Happy New Year! Welcome to our new forums!
WA #1.....word association